Winform iamge flashes briefly and disappears - winforms

New to winform, so excuse the elementary question:
I added a picture box on the form, initially hidden. In response to a button click, if certain condition is true, I make the picture visible.
The problem is when I click the button and the condition is true, it shows the broken image ("Error Image"). On the design page, the image is displayed fine.
private void btnTest_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textbox1.Text))
{
//Controls.Add(image1);
image1.Show();
//image1.Visible = true;
}
The image is part of the project; its build action is set to "Embedded Resource" and "Copy to output directory" is set to "do not copy". Also, when I check the project resource page, I see the image and its "Persistence" property is set to "Embedded in .resex".
Not sure what else I can do aside from copying the image to output directory.

I was modifying the properties, in VS properties panel, under "Asynchronous" and setting up picture box's image location. I did not set up image location under "Image"!! Dumb newb question!

Related

CEF browser showing old content on the window

I was creating a browser window for my WPF application. During the visibility change I am loading the URL, but when I change the URL content and load the same URL it is showing previous content first, then after a blinking it shows the updated data.
void OnWindowVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (!IsBrowserInitialized) return;
if (window.Visibility == Visibility.Visible)
{
Dispatcher.BeginInvoke(new Action(() =>
{
LoadNewUrl();
window.Activate();
}));
}
else
{
Dispatcher.BeginInvoke(new Action(() =>
{
ChromeBrowser.LoadHtml("<html><body><h1></h1></body></html>");
}));
}
}
Suppose the URL contains "ABCD" as data. First time it is showing the correct content. After the update the data becomes "ABCDEF". Now on Load() the initial content is showing then the updated content.
Is there anything else I need to do for avoiding this issue?
I'm not sure what LoadHtml() does, it's not a part of the native CEF API. In any case the blank page is about:blank, i.e. ChromeBrowser.Load("about:blank").
Are you aware of stopping all activities in the hidden browser? It seems to be the issue - you load an empty page and hide the window, the browser stops any activities, then you activate the window and still see an old content, then an empty page causes "blinking", and finally a new content is shown.
You should catch change visibility request, cancel it, load about:blank and hide the window on load completion. The client handler has appropriate events.

Add a label to a panel or groupbox on button click

Is there a way to add a label or content to a panel/groupbox once a button has been clicked ?
So for instance, lets say I wrote some content in the above textbox and I hit Post button. Is there a way to add this content in the below panel/groupbox ? And if I can't add to a panel/groupbox, which tool should I use ?
How to Display content from a TextBox when Clicked.
Please check on your MSVC under Solution Properties for all the Buttons, Text and Panels properties. Example; Button1, TextBox1 etc. Then make functions calls and assignments by these reference.
protected void Button1_Click(object sender, EventArgs e)
{
MessageBox.Show(" "+ TextBox1.Text);
}
This will display your content to a Pop up window. You can also try TextBox1.Content instead of TextBox1.Text.
NB: This code should be placed on your POST button.

WPF Tab_selectionChanged

I have this strange issue I am facing currently.
I have created an WPF application based on WPF page navigation. I have few button and depending on the button click the the user is navigated to respective WPF page.
In these WPF pages I have Tab controls and have used selectionchanged event handler to perform some task.
Now to the issue,
When I try to go a particular page, the selectionchanged event is also executed even before the page is loaded completely, I have tried to use the windows.loaded (based on the answer provided to my previous question - here) - I have no luck.
[I am using WPF Navigation framework]
Somehow the selectionchanged event is executing twice.
How do I stop this from happening?
I think you should check SelectionChange.AddedItems and SelectionChange.RemovedItems to find the difference between these to firings. I guess that when you select a page, SelectionChange.RemovedItems==0 while when you click on a tabItem to select it, SelectionChange.RemovedItems==1. if so just write:
if (SelectionChange.RemovedItems==0)
return;
Edit1: Please see the first comment.
Edit 2
void tablcontrol_SelectionChange(object sender, SelectionChangedEventArgs e)
{
if (e.RemovedItems.Count == 0)
{
// I guess this is the event that happens when a page is selected
// in this case just a TabItem is added to the selection
// and nothing is removed, so do nothing
return;
}
// if you are here, it means that this is another selection changed event
// so Perform those tasks that you mentioned in your question
}

updating UI in windows phone 7

In method that is working in the background, i have two important lines :
createPopup();
MessageBox.Show(sth);
more lines
more lines
createPopup() just creates a popup, adds a grid as a child and shows popup.
My question is, why first shows up messageBox, then shows up Popup, which appears after all lines in this method done ? How could I make this popup to show before all lines in this method will be done ?
All the UI changes are normally queued up and will be shown at once on the screen.
And this does not include MessageBox. So it shows up immediately and prevents the execution, until user clicks on Ok. Hence eventhough your popUP is first executed, it will be shown in the UI only after the MessageBox.
For your problem, Try placing your MessageBox.Show(something) in a separate thread.
createPopup();
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("some message");
});
more lines
more lines
Give it a try. I am not sure whether it solves your problem or not as I dnt know the code in createPopUp() method.
Creating the pop-up, does not actually draw it on the screen until the Layout event. If you want to ensure that the pop-up has been drawn before you display the pop-up, attach an event handler to the pop-up's LayoutUpdated event and display the message box from within that event handler. Be sure to detach the event handler as well or you will see multiple message boxes.
public InitPage()
{
Popup popup = new Popup();
popup.LayoutUpdated += popup_LayoutUpdated;
LayoutRoot.Controls.Add(popup);
}
void popup_LayoutUpdated(object sender, object e)
{
popup_LayoutUpdated -= popup_LayoutUpdated;
MessageBox.Show("hello");
}

UI Design Concepts in WinForms

In one certain case I want to disable the tabpannel so that the controlls in the tab panel are disabled.
I want to disable the tab pannel but still I want ennable the controls in tab pannel.the need is User cannot switch over to the annother tabpannel in a certain senerio.
How can I do this requirement?.
by
dinesh
Use something besides a tab panel.
It is not standard behavior for a tab panel to have one tab "stuck" so that the user cannot move to the other tabs. You're going to throw users off if you do this.
What you are after sounds like a modal dialog. It sounds like you don't want the users to move away from a certain screen until they're doing entering some data or some such. The modal dialog is built for this purpose.
There is no direct way to disable Tab Page, only you can remove it. But in your case, you can't remove the Tab, So I think you need to put some code in the Tab_SelectionIndex change event. And when ever the Tab index comes, set it back to another one.
Try this code
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 1)
{
tabControl1.SelectedIndex = -1;
}
}
In addition to anuraj's answer, set the colour of the tab text to the disabled text colour state, so it is a visual cue it is "disabled".

Resources