|
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
|
|
|
|
|
Thanks Guys,
With your help i have found a working solution for me. .NET 2.0 framework. The var i cannot use yet
private void butSave_Click(object sender, EventArgs e)
{
try
{
bool YesNo = xxxSaveData();
if (YesNo)
{
if (Parent is Form)
{
Form myParent = (Form)Parent;
myParent.Close();
}
}
}
catch (Exception ex)
{
ExceptionManager.Publish(ex);
}
}
Kind regards,
Marcel Vreuls
MarcelVreuls.com
<<A good idea can change your life>>
|
|
|
|
|
Haven't you read the comments?
Change to:
private void butSave_Click(object sender, EventArgs e)
{
try
{
bool YesNo = xxxSaveData();
if (YesNo)
{
Control ctrlSender = sender;
(ctrlSender.TopLevelControl as Form).Close();
}
}
catch (Exception ex)
{
ExceptionManager.Publish(ex);
}
}
or your code depends on the control beeing placed on the form directly.
|
|
|
|
|
Hi All,
For a few weeks now i am strungling with an anoying issue. I have a MDI Parent form. From this form i have child forms (normal winforms) which i open. These forms are opened withing the MDI parent form. So far so so good. And know my problem. From this childform i open a new form through a button. There is for me no way to open this form as mdi child form because its parent is also an mdi child. I have looked for looping throug form collections but cannot find the solution to my problem.
How can i detect the MDI Parent of my application from within all open forms.
Thanks Marcel Vreuls
Kind regards,
Marcel Vreuls
MarcelVreuls.com
<<A good idea can change your life>>
|
|
|
|
|
Well, since you should know the parent form's class name this is what I've done recently. I can't guarantee that it is the best method of doing it but I also haven't found any other solution:
private void Button1_Click(object sender, EventArgs e)
{
((AppForm)this.MdiParent).SomeMethodToOpenChild();
}
Casting the current child form's 'Form MdiParent' to the application's form type, then calling a method that opens the necessary child window. Like I said, I don't know how safe that is. But I believe you could check ahead of time like this:
if (this.MdiParent is AppForm)
((AppForm)this.MdiParent).SomeMethodToOpenChild();
I hope this at least gets you going in the right direction.
|
|
|
|
|
If the form is an MdiChild, you can get a reference to its parent using the MdiParent property. If you want to set another form as a child of the same parent, it's pretty easy
If you want a MdiChild form to be both a MdiChild to one Parent and a MdiParent to another child form, you can't. It's not supported. A form cannot be both a MdiChild and MdiParent at the same time.
|
|
|
|
|
Great answer Dave.
The mind is like a parachute. It doesn’t work unless it’s open.
|
|
|
|
|
hi i am trying to do malloc in vs.net 2005 c# window form as i am trying to dynamically allocate memory for a array which i dont know the size.
am i missing a reference or something?
or is there some other way to do it?
please advice
|
|
|
|