Jump to content
Xtreme .Net Talk

ToniMontana

Avatar/Signature
  • Posts

    29
  • Joined

  • Last visited

Everything posted by ToniMontana

  1. Hi all, I want to show a tree-structure with a treeview-control, which is a cool thing to do. The first problem is/was: The GUI runs on another machine, so the data has to be transported via remoting. I want to send an XmlDocument-Object, but this is not serializable! No problem, I can convert it to a string an then I send. The second problem is: I want to be able to update a part of the treeview too! So I must send the path of the selected treeview-node to the server, and there I must extract the corresponding node out of the XmlDocument and send it again. I can select this node via SelectNode() or similar. I will get a XmlNode-Object which holds the data of one node and all of it's children, if it has some. Now I must convert the XmlNode into an XmlDocument again, but how? Or does anybody have a better solution for my project?
  2. Hi Michelle, for me it is a little bit unclear what you want do do with your code. You say "executing the class".... !?!? My idea is: Try to make another project in which you start again with a very easy version of that problem. Threading can be a difficult thing and you must bear in mind, that you cannot change a control (e.g. a textbox) from another thread so easy. You HAVE TO USE BeginInvoke() or Invoke() to make changes to the so called "UI-thread", that is the thread, in which all your controls run. Try to read some things in the net: http://www.yoda.arachsys.com/csharp/multithreading.html http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfmultithreadedapp.asp Info from MSDN: >> Controls in Windows Forms are bound to a specific thread and are not thread safe. Therefore, if you are calling a control's method from a different thread, you must use one of the control's invoke methods to marshal the call to the proper thread. This property can be used to determine if you must call an invoke method, which can be useful if you do not know what thread owns a control. There are four methods on a control that are safe to call from any thread: Invoke, BeginInvoke, EndInvoke and CreateGraphics. For all other method calls, you should use one of these invoke methods when calling from a different thread. Windows Forms uses the single-threaded apartment (STA) model because Windows Forms is based on native Win32 windows that are inherently apartment-threaded. The STA model implies that a window can be created on any thread, but it cannot switch threads once created, and all function calls to it must occur on its creation thread. Outside Windows Forms, classes in the .NET Framework use the free threading model. <<
  3. This will give you a random number: /// <summary> /// Returns a random number (0<=x<max) /// </summary> private int CreateRandomNumber(int max) { // advance timer: Thread.Sleep(1); // create random number: Random autoRand = new Random(); return autoRand.Next() % max; }
  4. Hi raduv, may be this will help you: http://www.syncfusion.com/FAQ/WinForms/FAQ_c73c.asp#q1039q Look for question+answer 42.9.
  5. You are right, Nerseus. Lottery is ****! (oh, that word is censored...) ;-)
  6. Thanks Joe Mamma. I will see...
  7. Hi PlausiblyDamp, hi Arch4ngel, the fact is: the property AcceptButton is a property of a form, not of a control. You have to say to the form, which the accept-button and cancel-buttons are. If you have a user-control like I have, and you switch off some buttons via buttonxyz.Enabled = false and the form gets the focus again, the system will assign the "accept" to the first enabled button of the user-control. You can see that, because the button then has an additional coloured frame. But I want to decide programmatically, which button is the accept-button. I dont know how to do that if the systems sets it by itself. To delete every "accept-button-functionality" of my user-control would help in this situation, then I would be able to set it later programmatically to a button, which is enabled then. @Arch4ngel: What do you mean by a "custom-control"? I already have a user-control, which is a class, derived from System.Windows.Forms.UserControl.
  8. Thanks for the replies. But it's not the problem to do "some action" at the visible-changed-event of my user-control. I must know HOW TO SWITCH OFF THE ACCEPT-BUTTON AND CANCEL-BUTTON. Any ideas?
  9. Hi, I have the following problem: In my mainForm I have several different user-controls, which I can control with "show", "hide" etc... I want to set the Acceptbutton of each user-control programatically just before it will be displayed with "show". For this reason I also need to disable the Acceptbutton of a user-control. But I saw that this isnt possible! If I display only one user-control in my form and click on it so that it gets the focus, then the first button of it will be the Acceptbutton automatically! How can I switch off this feature? If I say user-control.AcceptButton = null nothing changes...
  10. Hi, I have tried the same with my VS.net in C# and cannot see that the windows is maximizing after double-clicking the title-bar. So, what is the problem?
  11. Here I have a question to all WinForms-experts ;-) In my app I try to realize the concept of having different fixed-size-areas of the main-form-window, say left-area middle- and right-area. In the left and right I want to display buttons, in the middle normal graphics and other machine-infos. To be able to display different content in each area, I designed these contents as usercontrols which fit in the left-area or middle-area and so on. The main-form-windows has a panel for each area, and in these panels I can plug the usercontrols (after creation) during runtime with the call: panelLeft.Controls.Add(usercontrolX) or panelRight.Controls.Add(usercontrolY) and so on. Now my question: Is there a way to do such things without these panels? Because the problem is: Every time I create a new usercontrol (via CreateInstance()), I MUST do the adding to the panel and this HAS TO BE DONE in the class of the main form window. But I want to do it somewhere else, I think this must be possible because I can ask for the reference of the main-form- window-panels via a property. But it doesnt work. It compiles but after adding a panel from outside it will not be shown correctly.
  12. There are many threads about this error in the net. Look in google for the words "cannot be copied to the run directory" and you will finde many comment and tips. Seems that the VisualStudio isnt bug free anyway... One bug message is from bill's company itself: http://support.microsoft.com/default.aspx?scid=kb;en-us;313512 ;-)
  13. Hi again, I found the solution of the problem and will describe it here for you: The event, which gives the userControl its data and should also switch the focus of a control was generated by my data-receive-thread, which is not the UI-thread!!! This cannot work, but some action do work: I could set the background color of a control or set a control to enabled/disabled but only the setting of the focus didn't work! So, I changed the code so that the data-receiving-thread calls the data-update of the form via Invoke() and a delegate and now it works! Here a schema for correct code to update a form initiated from another thread: if (this.InvokeRequired) { this.BeginInvoke(new DelegateUpdateForm(this.UpdateForm), new object[] { message } ); } else { UpdateForm(message); } info from MSDN: Controls in Windows Forms are bound to a specific thread and are not thread safe. Therefore, if you are calling a control's method from a different thread, you must use one of the control's invoke methods to marshal the call to the proper thread. This property can be used to determine if you must call an invoke method, which can be useful if you do not know what thread owns a control. There are four methods on a control that are safe to call from any thread: Invoke, BeginInvoke, EndInvoke and CreateGraphics. For all other method calls, you should use one of these invoke methods when calling from a different thread. Windows Forms uses the single-threaded apartment (STA) model because Windows Forms is based on native Win32 windows that are inherently apartment-threaded. The STA model implies that a window can be created on any thread, but it cannot switch threads once created, and all function calls to it must occur on its creation thread. Outside Windows Forms, classes in the .NET Framework use the free threading model.
  14. Hi, I have a mainform with a panel in it. In this panel I added a UserControl with panel.Controls.Add(UserControl), which is dynamically loaded from my "plug-in".dll. In the UserControl I implemented a mechanism, with which I can send data to display. Every time, the UserControl gets data, it will get the data-object via a data-changed-event. The UserControl can then retrieve the data from the event-object. With this data comes state-information for the controls too. E.g. in the UserControl are several buttons and a textbox. If I send data to set the focus to the textbox, nothing happens! BUT: If I use the same code in a "button-click"-method, I can put the focus to the textbox! Why is it a difference??? And how can I switch the focus to the textbox on receiving a data-event??? Here is some code: The following code will be called after a data event happened: setFocusSuccessful = this.timerTextBox.Focus(); Debug.WriteLine("<this.timerTextBox.Focus()> called: " + setFocusSuccessful.ToString()); The output is: false This code is in the button-click-method: setFocusSuccessful = this.timerTextBox.Focus(); Debug.WriteLine("<this.timerTextBox.Focus()> called: " + setFocusSuccessful.ToString()); The output is: true Yes, you are right, it is the same code in both cases. So there must be a difference if I call the code from the button-click-method! The question is now: What happens additionally in this method, what code is run from the .NET-framework in a button-click-method which the user doesnt know???
  15. I use it in a WinForms-App and it works.
  16. I think you only have to set the backcolor of the control to Color.Transparent.
  17. Hi, I am no expert on this, but would first go through the collection only to mark the items which should be deleted. And then, in a second run, delete them. You can easily put the references of the datasets which should be deleted in an arraylist. Hope this helps,
  18. Ok, I found the answer by myself: The method bringToFront does only work for the panel, because it contains the userControl. For showing a particular userControl I must first get the containing Panel and then... Control panel = userControl.Parent; panel.BringToFront(); userControl.Show();
  19. Hi all, I have a form with 3 areas, which are 3 panels: leftPanel, centerPanel and rightPanel. The app creates userControls which are then placed onto the panels with the call this.centerPanel.Controls.Add(userControl) for example. Then I can call Show or Hide for each userControl. So far it works fine. BUT: Now I want to have overlapping panels. But I don't know how to bring a userControl to front, userControl.BringToFront() does not work. Show() does not work either. I tried both, but it doesnt work.... Any idea?
  20. Hi, how can I get the names of my buttons etc. of a user-control while running the program? I know it is possible via reflection. E.g.: I call a method in a user-control and here I want to check, whether it has a button called "btnXY".
  21. Hi all, how can I realize the usage of function keys in my win forms application, so that I can Show or Hide different panels, which all have different buttons. But these buttons should all be pressed by the usage of the function keys.
  22. Hi, another noob-question: How can I make a button to the default- Button of the containing form? I think the default-button is the one which can be pressed by using the return-key.
  23. Hi, thank you for the reply, but this will not solve the problem. Imagine you have many different controls in a form and some textBoxes too, lets say 10. And let us assume that 5 of these textBoxes belog to a group and only these 5 must be changed in a particular way. How can I do this without having to write: switch(textboxName) { case "T1": t1.Text = "Hello"; break; .... } How can I do that with a textBox-Array?? I really dont know, I am a noob... I know from VB that it creates an array if you copy&paste a control. Is this the same in Visual-Studio for C# ?
  24. Hi all, I think the most used WinForms-control for input of a number is the normal "textBox", right? So the number I have put in is a string internally which I can get if I use the .Text-property. But how can I convert this to a real number like int or double? To increase the number of textBox "mytxtBox" I have to write a code like this (which works correctly): if(this.mytxtBox.Text == "") this.mytxtBox.Text = "0"; currentValue = System.Convert.ToInt32(this.mytxtBox.Text); currentValue += 3; // to write the increased number back into the textBox: this.mytxtBox.Text = currentValue.ToString(); My question: Am I on the right way or is there a shorter better way to input a number in a GUI?
  25. Hi all, I want to change a set of similar controls in a form. How can I create a reference (like a C-pointer) to switch from one control to the next? Or do I have to organize them as a control-array? How can I do that, what is the best way?
×
×
  • Create New...