|
I tried your way its not working, any other suggestion.
|
|
|
|
|
... you are allocating ("New") another instance in your Ok and Closed-Handler - this is a simple mistake. Your code smells like "beginner-style" maybe you want to learn about "variable scope"?
Solution:
1. Make a public property for Form2 which will give you the textbox.Text (you did that)
2. Read the property after showing the Form
-> Simple, isn't it?
3. Sit down and read a book about programming before you do further coding... (variable scope is always a thing you need to know, in any language)
Public Class Form1
Public _form2 As Form2 = New Form2
Private Sub btnList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnList.Click
_form2.Show()
tbxVal.Text = _form2.textBox1
End Sub
Public WriteOnly Property _textBox() As String
Set(ByVal Value As String)
tbxVal.Text = Value
End Set
End Property
End Class
|
|
|
|
|
Knowledge has no boundaries any one who struggles for it he gains the knowledge, one should not underestimate the person on the other side and should not pass remarks that hurt other poeple or discourage people.
You should show respect to people who are in your type of field. If you donot like to answer any question you are free to do that.
For your information i have already done it without your support.
Kind Regards
Mirza
|
|
|
|
|
I suggest you take the advice given to you, even when at first sight you don't like it much.
As for your problem, there is at least a dozen ways to "solve" it, unfortunately only one or two of these ways are decent, all others are bad, i.e. they work in a simple situation and will bite you when things become more complex.
It takes time and experience to learn it all, and most of all an open mind.
|
|
|
|
|
<Thank you for the advice, i always appriciate good advice, you are right there are and its true
also time is the only teacher, and most of all with an open mind is true and will to strugle in life and always give your thoughts a possitive direction, if one do that ones mind will always be open. >
|
|
|
|
|
This is a really common problem, and it's almost always answered incorrectly. Never, ever, attempt to use the instance scope to control the passing backwards and forwards of data between two modeless forms. Look to use delegate/events instead, and have the first form subscribe to an event on the second form which will be fired when it needs to return the data.
|
|
|
|
|
I have a method that queues a number of processes in a separate thread, long running stored procs. I want to disable controls and warn the user that the thread is still active so they cannot close the application while the thread is running.
I have a static class (clsMain) that has the property and the change event that is set from within the processing thread.
public static event EventHandler ProcessFlagChanged;
private static bool _IsProcessing;
public static bool IsProcessing
{
get { return _IsProcessing; }
set
{
_IsProcessing = value;
if (ProcessFlagChanged != null)
ProcessFlagChanged(null, EventArgs.Empty);
}
}
I now want to bind a buttons enabled value to clsMain.IsProcessing. This naturally does not work because clsMain is a type.
btnLoadPool.DataBindings.Add(new Binding("Enabled", clsMain, "IsProcessing"));
Is the design flawed or do I need to have another variable/event on the form to bind to?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Why do you choose a static class? If you drop the statics and instantiate it, all would be well.
And if you only want to have one instance at most, look for the singleton pattern.
|
|
|
|
|
Luc Pattyn wrote: Why do you choose a static class?
Well, because it's already there. I do want to reference this from at least 3 different places but that is a minor issue.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
smells like static abuse. OO requires you explicitly pass a reference around for the objects you want to use.
|
|
|
|
|
Luc Pattyn wrote: smells like static abuse
Yeah, yeah, where are my global variables, I'll revert to variant shortly.
Did the job properly, declared a class, passed the class from the main form to the processing form, used a BGW thread to do the work and everything hangs together nicely.
I don't use a lot of threading, I live behind the firewall and don't use a WAN, so latency is rarely an issue. This is slowly changing and the move to Silverlight is going to be interesting!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hi i am using vs.net 2005 with c# window form
does anyone know how to make all the control inside the window form scale with the form
e.g when i enlarge the window form by 20% so will the control scale with it and also the text
|
|
|
|
|
Scaling is not a very definitive term in this case. You need to describe what each child control is. Is this for "zomming" graphics of some sort? If so, read up on the PictureBox functionality.
|
|
|
|
|
If it is just increase in the size of controls, proper anchoring/docking would do. You can use the TableLayoutPanel, it makes life easier.
For the text, you will have to redraw it using the methods in the Graphics class. You will need to use MeasureString and DrawString methods.
|
|
|
|
|
Ok, others said what you have to do (doking, manual resizing of the fonts and graphics, etc.)
What comes to my mind, when I hear such a requirement is: Is this really what you should do?
How many applications have you seen behaving like that (no dynamic layout but real resizing of a static layout)?
And if this is real necessary (because you are writing an app for visually impaired, or whatever) you are maybe using the wrong platform. (e.g Scaling is very simple to do with WPF/Silverlight)
|
|
|
|
|
Hi all,
i'm using ASP.net C# Windows Forms to develope an application and i want to know how can i set icon for .exe file?
not the icon that appear on taskbar after douple click on .exe file but i mean the icon for .exe file itself.
i want to change the normal icon.
Thanks
Abdullah
|
|
|
|
|
Abdullah S. Abdelhay wrote: how can i set icon for .exe file?
Change the setting in the properties of your main form.
It's time for a new signature.
|
|
|
|
|
If compiling from command line ( csc ) use the switch /win32icon.
If developing in Visual Studio, go to Project, Properties, the in the Application Tab where is says Icon.
|
|
|
|
|
Hi All,
Just another question. I have several winforms with a usercontrol on it. I re-use these usercontrols on several different forms. SO far so good, but what i would like to do is close the usercontrol AND form on which it resides from a button on the usercontrol. I have been experimenting with events but until now i cannot get it done.
Any ideas? suggestions??
Best regads, marcel
Kind regards,
Marcel Vreuls
MarcelVreuls.com
<<A good idea can change your life>>
|
|
|
|
|
So using a button on the UserControl you want to close its parent form? I think it would be as simple as calling "this.Parent.Close()". I don't know how this wouldn't work since the UserControl's parent should be the form that contains it.
|
|
|
|
|
One small issue with this is that the parent might not be the Form, it might be, for example, a Panel that might also be a hosted in another Panel. So if this scenario is possible (now or later in the future), the OP should either keep looking for the Form as in the code below or just give the UserControl a reference to the Form during initialization or something so it closes it directly, which is better (constant time instead of linear time).
var parent = this.Parent;
while (!(parent is Form))
parent = parent.Parent;
parent.Close();
Eslam Afifi
|
|
|
|
|
Oh no! Don't do it like this!!!
use
Control.TopLevelControl
property!!!
|
|
|
|
|
Yeah, Luc Pattyn's reply[^] reminded me of it. Of course a direct reference to the Form is better, that's what I said in my reply, I just forgot that the reference is already there as the TopLevelControl property provided by the framework.
Eslam Afifi
|
|
|
|
|
as the others said, however you could take advantage of Control.TopLevelControl to get to the parent Form.
|
|
|
|
|
Hehe, very true. See, this is why I love CP. Learn something new everyday! :-P
|
|
|
|