|
When opening the modal dialog how do I allow the mainForm to continue processing?
I have always thought that the normal way of doing it was to create a backgroundworker, have it do the processing and update a progress bar on the main form.
Glen Harvy
|
|
|
|
|
Hi Glen,
Disabling a form can be handled in several ways: you can disable all the Controls
(not recommended), hide the form, or make sure it can't get focus (that is exactly what
you get with a modal dialog).
There are many ways to get the work done; using a Thread, a ThreadPool thread, or a
BackgroundWorker are amongst them. And that is independent of your form situation;
the thread or whatever simply runs in the background; it gets organized by either the
form or the modal dialog, your choice.
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi,
I have made a custom class to populate a TreeView thru its ItemsSource. That class heritates ObservableCollection.
The thing is that its nodes doesnt seem to be TreeViewItems because i cant apply code that works for normal treeviewitems.
I'm talking about code to do right click select, etc.
What i really want is to be able to automaticly select a node when i right click it, and then open the context menu.
I can do this perfectly using the left button to select the node and then using the right click to access the context menu.
The problem is that i cant use directly the right button which is something typical in windows enviorment.
The code i'm using to achieve that is the following:
Code Snippet
tvNetworkExplorer.AddHandler(TreeViewItem.MouseDownEvent, new MouseButtonEventHandler(TvNetworkExplorer_MouseDown));
private void TvNetworkExplorer_MouseDown(object sender, MouseButtonEventArgs e)
{
TreeViewItem item = e.Source as TreeViewItem;
if (e.RightButton == MouseButtonState.Pressed)
{
item.IsSelected = true;
}
}
I think this happens because the items are not tree view items, as stated before, they are items from an observable collection of a custom type.
How can i make such behaviour to happen?
The problem is that even using the visual tree help i always get the first node.
I need to show you the big picture. Maybe i have something really small failing:
XAML:
<treeview width="Auto" height="Auto" dockpanel.dock="Top" cliptobounds="False" snapstodevicepixels="False" borderbrush="{x:Null}" fontweight="Normal" x:name="tvNetworkExplorer" background="{x:Null}" margin="5,5,5,5">
<treeview.resources>
<hierarchicaldatatemplate datatype="{x:Type src:Group}" itemssource="{Binding Path=Items}">
<textblock text="{Binding Path=Name}">
<hierarchicaldatatemplate datatype="{x:Type src:GroupItem}" itemssource="{Binding Path=List}">
<textblock text="{Binding Path=Title}">
<datatemplate datatype="{x:Type srcStick out tonguelayer}">
<textblock text="{Binding Path=Name}">
<datatemplate datatype="{x:Type src:Behaviour}">
<textblock text="{Binding Path=Name}">
<treeviewitem itemssource="{Binding}" header="Network">
Code:
tvNetworkExplorer.DataContext = networkExplorer;
// Events
tvNetworkExplorer.AddHandler(TreeViewItem.MouseDownEvent, new MouseButtonEventHandler(TvNetworkExplorer_MouseDown));
tvNetworkExplorer.SelectedItemChanged += new RoutedPropertyChangedEventHandler<object>(TvNetworkExplorer_SelectedItemChanged);
private void TvNetworkExplorer_MouseDown(object sender, MouseButtonEventArgs e)
{
//TreeViewItem item = e.Source as TreeViewItem;
TreeView tv = (TreeView) sender;
TreeViewItem obj = (TreeViewItem) GetBoundItemFromPoint(tv, e.GetPosition(tv));
Console.WriteLine(obj.Name);
//Console.WriteLine(item.ToString());
//if (e.RightButton == MouseButtonState.Pressed)
//{
// item.IsSelected = true;
//}
}
static private object GetBoundItemFromPoint(TreeView tv, Point point)
{
UIElement element = tv.InputHitTest(point) as UIElement;
while (element != null)
{
if (element == tv)
return null;
object item = tv.ItemContainerGenerator.ItemFromContainer(element);
bool itemFound = !object.ReferenceEquals(item, DependencyProperty.UnsetValue);
if (itemFound)
return item;
else
element = VisualTreeHelper.GetParent(element) as UIElement;
}
return null;
}
The result of the right click is always the first treeviewitem, the one that has "Network" as header in the XAML.
But this is a contradiction as i can select the nodes in the tree with the left click.
Help here, please...
Best regards,
Nuno
|
|
|
|
|
I'm facing the same problem. I somehow managed to get it selected in the similar way and opened the contextmenu like
TreeViewItem.ContextMenu.IsOpen=true;
but the problem that occurred was, the commands bindings to the menu items(in xaml) don't work.
|
|
|
|
|
hi,
I want to serialize a class which has the two kinds of elements. Custom elements (non graphic and made by me, which are serializable by the XmlSerializer), and UI Elements from the WPF. The class which i want to serialize is this:
Code Snippet
public class Region : ISerializable
{
private Control _control;
public Control Control
{
get { return _control; }
set { _control = value; }
}
private Border _bounds;
public Border Bounds
{
get { return _bounds; }
set { _bounds = value; }
}
public Region()
{
}
///
/// Initializes a new instance of the class.
///
public Region(Border bounds)
{
_bounds = bounds;
}
public Region(SerializationInfo info, StreamingContext ctxt)
{
this._control = (Control)info.GetValue("Control", typeof(Control));
this._bounds = (Border)XamlReader.Load(new XmlTextReader(new StringReader((string)info.GetValue("Bounds", typeof(string)))));
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("Control", this._control);
info.AddValue("Bounds", XamlWriter.Save(_bounds));
}
}
As you can see, this class is composed by a Control (custom made class specified by me) and a Border (UI Element). The class was serializable if i didnt have the border on it.
My attempt was to override the Iserialize methods in order to have serialization of the border based on XamlWriter.Save but it gives me error before getting there, in the following line:
Code Snippet
System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(Region));
With the message:
Code Snippet
"There was an error reflecting property 'Bounds'."
How can i solve this problem?
Thx,
Nuno
|
|
|
|
|
Dictionary<string, listviewitem=""> list = new Dictionary<string, listviewitem="">();
String nameAndJob, Job, line, name;
Int32 pages;
ListViewItem item1;
foreach (ListViewItem lvi in listView2.Items)
{
nameAndJob = string.Concat(lvi.SubItems[0].Text);
if (!list.ContainsKey(nameAndJob)) list.Add(nameAndJob, lvi);
Job = string.Concat(lvi.SubItems[1].Text);
if (!list.ContainsKey(Job)) list.Add(Job, lvi);
}
using (StreamReader sr = new StreamReader(path1 + "/personalpr.txt"))
{
while (sr.Peek() > 0)
{
line = sr.ReadLine();
if (line == "#")
{
name = sr.ReadLine();
nameAndJob = string.Concat(name);
Job = string.Concat(name);
if (list.ContainsKey(nameAndJob))
{
item1 = list[nameAndJob];
item1 = list[Job];
item1.SubItems[1].Text = sr.ReadLine();
item1.SubItems[3].Text = sr.ReadLine();
item1.SubItems[5].Text = sr.ReadLine();
}
int result = 0;
foreach (ListViewItem lvi in listView2.Items)
{
result += int.Parse(lvi.SubItems[2].ToString()) - int.Parse(lvi.SubItems[3].ToString()); ????????????????????
////I want to calculate lvi.subitems[2] - lvi.subitems[3] and pass the result to subitems[3].
}
item1.SubItems[3] = result.ToString();???????
}
}
}
}
Can i delete this readline from .txt file after this use??? and how??
Thanks all!! ;)
|
|
|
|
|
As you are reading the input file, you should generate a corresponding output file. Copy only the data you want to keep from the input file to the output file. When you have finished reading the input file, overwrite it with the output file.
aul
|
|
|
|
|
Any idea how to encode Arabic letters after retrieving them from a database?? I'm using Oracle8i and I made sure they're stored correctly and can view them correctly from sql*plus but not from a windows form.
Please help
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hello Muammar,
Have you set a correct Unicode Font to the Control which should show the text?
All the best,
Martin
|
|
|
|
|
Thanks Martin , I should try that
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hi Everyone,
I want to create something similar to www.20q.net but for business application. I know it uses a neural net (for which I have already created a library). But a neural net alone is not enough.
Can someone point out to me how I could design this 20 questions app and what algorithm/data structures I should use?
Any help would be appreciated!
Regards,
Andre
|
|
|
|
|
Hi,
Use Frameset and frame HTML tags.
For further clarification can mail me suveen.kulshreshtha@gmail.com or
mayur.mehta@indiatimes.com
|
|
|
|
|
Hi Suveen,
Thanks for the reply but I think you are misunderstanding.
My problem is not physical implementation or or even close to presentation layer. What I want to know is what logical design should I follow and how do I translate the problem space domain into a model.
In other words, how do I use a genetic algorithm and a neural network to teach my app.
Regards,
Andre
|
|
|
|
|
Does anyone know if the filename can be set programatically and the 'Save as' dialog-box suppressed when i want to print something with "Microsoft image printer"?
P.S. I am working on a Cristal Report project and i am using PrintToPrinter() function.
Thank you very much!
--------------------------------
visit: http://pmartike.deviantart.com/
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
button2.Enabled = false;
Thread.Sleep(2000);
button2.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Button 2");
}
in the above code, when i click the button2 while the sleep i on, after the sleep is over, i get the message box in the button2 click event.
what is the function of setting enable = false then?
how to prevent this?
thanks
|
|
|
|
|
You are putting the current Thread in sleep stage so,
Your button2 is disabled but when you click on it,
The event is not fired. because the thread is sleep and it will not accept the click event it actually Fire the event when the thread is in running mode again so at that time the button2 is enabled.
if you are still confused then reply this message
Best Regards,
Chetan Patel
|
|
|
|
|
i dont want to fire the button2 click even when it is disabled. how do i do it?
|
|
|
|
|
Hello,
You have to set the "Enabled" property before the user clicks the button.
If you want to make a validation on the/an event itselfe,
I would suggest inherit your own Button from System.Windows.Forms.Button.
Use a validation method which uses Flags or some other stuff.
Override OnMouseDown, which checks the validation method and calls the base method or not!
Not calling the base method of OnMouseDown, will prevent the click event from fireing!
See this code example:
public class SpecialButton : System.Windows.Forms.Button
{
public SpecialButton()
{
}
private bool flag1 = true;
public bool Flag1
{
get
{
return flag1;
}
set
{
if(value!=flag1)
flag1 = value;
}
}
private bool flag2 = true;
public bool Flag2
{
get
{
return flag2;
}
set
{
if(value!=flag2)
flag2 = value;
}
}
private bool ValidateClick()
{
return Flag1&&Flag2;
}
protected override void OnMouseDown(MouseEventArgs e)
{
if(ValidateClick())
{
base.OnMouseDown (e);
}
else
{
}
}
}
Hope it helps!
All the best,
Martin
|
|
|
|
|
Hi,
the way you do it, button2 is not disabled at all, since the 2-second period it is disabled
you also "stop the world" by holding off the GUI thread.
don't put Thread.Sleep() in an event handler, it stops the GUI, which you never want to
happen. Instead, disable button2 and organize something to re-enable the button later.
For instance launch a Windows.Forms.Timer; when that timer expires, re-enable button2.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
hi
i was created a pdf help for my application and now want to by click a button show pdf file.
how can show a pdf file in C#?
tanks
|
|
|
|
|
Create Process and start the process by giving obsolute path of PDF file.
Process.Start ("x:\\sample.pdf");
Thanks
|
|
|
|
|
With the proper mention that you must have a PDF reader installed on your machine and it must be registered with the "pdf" extension.
|
|
|
|
|
Alternatively you can use a WebBrowser Control (so you can show PDF inside your app);
this too assumes you have a PDF reader installed.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
hi Luc Pattyn
your suggestion was very interest for me.
tanks so much
|
|
|
|
|
Hi.
Since ".net reflector" can decompile the assembly which means that all of the source can be restored, does any one know how to avoid that? since i have encryption keys stored in the assembly and can by seen with the .net reflector?
This has been bothering me for a few month.
Thanks.
|
|
|
|