|
|
You need to get a reference to the form in some way.
Form1.textOut.Text = ... doesn't work because you're addressing the class definition itself, not an instance of it. Creating a new Form1 object in Other won't work either (although it will compile) because it will be an entirely separate intance of Form1, not the one on your screen.
I don't know how your app is set up, but this should give you an idea of how to go about it:
public class Form1{
public Form1(){
...
Other other = new Other(this);
}
}
public class Other{
private Form1 frm1;
public Other(Form1 frm){
frm1 = frm;
}
public void WriteText(){
frm1.textOut.Text = "Howdy!";
}
}
In that code, you're giving Other a reference to the Form1 instance you're dealing with in its constructor, which is then being saved for future reference in a private field.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Hello,
I have a tab control with five tabpages. On the fifth tabpage I placed some controls (text boxes) out of the tabpages client area. Now, from what I understand, with the autoscroll option on, if there are controls outside of the client area, a scrollbar will appear so that you can scroll and see them. However, when I check the tabpage, I can scroll down to the unseen controls but no scrollbar appears. I use the mouse wheel to go down but I would like the scroll bar to appear so that ppl know that there is more to be seen. Does anyone know why it is not being drawn?
Also, is there an option I can set so that text boxes can only accept integers or at least put up a message when the text box loses focus and the user put in some non-number chars, or do I have to validate that myself?
Thanx for the help,
-Flack
|
|
|
|
|
The TabPage won't display scroll bars, but the Panel will. Dock a Panel in your TabPage and add your controls to that instead (cutting and pasting controls works in VS.NET, but you'll have to re-hookup any event handlers).
For the second question, you can handle the TextChanged event and validate the characters one by one (using, perhaps, Char.IsDigit ) - which will also validate (and optionally throw an exception) text when assigned programmatically, or for user input just handle the KeyDown event and validate the Keys enumeration passed with the KeyEventArgs .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I am wondering if I create a diffgram dataset and I save the dataset to file and then want to commit the dataset to the database. I would assume that I would use a DataAdapter to help commit changes to db, correct?
Is there any special command in the DataAdapter in order to save dataset to database outside of the Update command? Like in the Update property is there any special option type that needs to be included in order to inform the DataAdapter what I am trying to accomplish?
Will a diffgram dataset work for Access as well as Sql Server?
Thanks,
JJ
|
|
|
|
|
MrJJKoolJ wrote:
Is there any special command in the DataAdapter in order to save dataset to database outside of the Update command?
I think you are talking about DataSet.GetChange() method. Also take a look at DataSet.Merge() , DataSet.Copy() too.
Mazy
"A useless but amusing fact is that if all the DNA in all the cells in a single human being were stretched out it would reach the moon and back eight thousand times." - Steve Jones
|
|
|
|
|
i want to create a live web radio station and i dont know where to start
pls help
cristiansje@yahoo.com
|
|
|
|
|
If you're familiar with programming you could investigate other sources (in different languages, like C++ and Delphi) if you can find any.
|
|
|
|
|
i didnt find any code for this this why i asked about it
|
|
|
|
|
I know people who have had success using http://www.shoutcast.com/ but I dont know much about it myself.
Good luck.
|
|
|
|
|
i know about them but need some basic concepts
|
|
|
|
|
As a MFC programmer I got used to be able to specify an UpdateCommandUI command handler that would take care of enabling/disabling my toolbar buttons and menu items, setting checkmarks in front of menuitems, select correct push buttons in toolbars etc. Is there any mechanism similar to this in .NET? I haven't been able to figure it out, or do I have to hard code this behaviour into every single event handler that's relevant?
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
dabs wrote:
do I have to hard code this behaviour into every single event handler that's relevant?
Write seprate method which update controls and simply call it whenever you need updating.
Mazy
No sig. available now.
|
|
|
|
|
|
Uwe Keim wrote:
You missed the "call" word
Corrected now.
Uwe Keim wrote:
but surely it is quite inefficient if you have large number of controls to update.
Yes, but I don't think any other way exists in C#.
Uwe Keim wrote:
I think MFC's version only call the apropriate handlers that are really needed (e.g. only the contents of ONE dropdown menu).
Its a long time that I haven't use MFC , but as muuch as I remeber it was not act like this too.
Mazy
"A useless but amusing fact is that if all the DNA in all the cells in a single human being were stretched out it would reach the moon and back eight thousand times." - Steve Jones
|
|
|
|
|
Has anyone ran into this before? When I try to load a xfdf into the ocx the control stops responding. The reader.exe has full support for xfdf, so I have not idea what to think.
|
|
|
|
|
I have a small library witch contains a few controls and one simple class. The class holds a vew variables and functions that the controls need and also manipulates with the controls itself (changes their text and color for example).
MyOwnPropertiesClass <---- Ctrl1/2/3 connect to this class.
| | |
Ctrl1 Ctrl2 Ctrl3
Because all controls in library exchange information through that one class, there must be only one instance of that class. It should be created just when the library is initialized or something like that. How is it possible ?
Best regards, Desmond
|
|
|
|
|
Create a singleton. Here's how:
Create a private static member variable of your class of the same type as your class and call it singleInstance or similar.
Create a static initialiser which is like a normal constructor but with the keyword static in front of it. In this method create a new instance of the class and assign it to the singleInstance member variable.
Modify your constructor so that it is private . This ensures that no one else can create your class.
Create a new static public get property called Instance or similar and return the singleInstance member variable.
The remainder of the class is as you would normally have it.
You have now created a singleton. Every time you want to use the class you access it through the Instance property. This version of a singleton will be created at application start up.
If you want to delay the initialisation until first use then you can remove the static initialiser and have the code for the Instance property check singleInstance == null in which case a new instance of the class is created and assigned to singleInstance first. Then it returns singleInstance as it did before.
Does this help?
--Colin Mackay--
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
Thanks, this seems to be exacly what I need. However, could You please show me a little (code) example of a static initializer ?
And -- Where could I find more info on static initializers ? I did a quick search, but didn't result much...
Regards, Desmond
|
|
|
|
|
desmond5 wrote:
Where could I find more info on static initializers ?
Sorry, my fault - I was using Java terminology. In C# they are actually called static constructors. See this MSDN document[^]
[Edit]Ooops! I fixed some bugs[/Edit]
public MySingletonClass
{
private static MySingletonClass onlyInstance;
static MySingletonClass()
{
onlyInstance = new MySingletonClass();
}
public MySingletonClass()
{
}
public MySingletonClass Instance
{
get
{
return onlyInstance;
}
}
}
--Colin Mackay--
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
Thanks. I also learned that these singletons has something to do with thread-safety (has something to do with multithreading) ... is this code compatible with that ?
|
|
|
|
|
desmond5 wrote:
singletons has something to do with thread-safety
I don't see why it cannot be used in a thead safety mechanism. However I've never used a singleton for that purpose.
For instance if you have a singleton that controls access to a shared resource then in each of you instance methods and properties (not the static ones) you can lock(this) to ensure that not other thread has access to your singleton while some sensitive operation is being carried out. See MSDN[^] for more information.
--Colin Mackay--
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
Or a shorter version:
public MySingletonClass{
public static readonly MySingletonClass Instance = new MySingletonClass();
private MySingletonClass()
{
}
}
Have a look at my latest article about Object Prevalence with Bamboo Prevalence.
|
|
|
|
|
public (static) fields EVIL!!!!!!
--Colin Mackay--
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|