|
I'm going to suggest that you use one of the design patterns here. One that I'm thinking might help is the Mediator pattern (have a look on Google to find it), but it basically looks like this:
public class Mediator
{
private Form1 _loginForm;
private Form2 _buddyForm;
public Form2 BuddyForm
{
get
{
if (_buddyForm == null)
_buddyForm = new Form2(this);
return _buddyForm;
}
}
public Form1 LoginForm
{
get
{
if (_loginForm == null)
_loginForm = new Form1(this);
return _loginForm;
}
}
public void Logout()
{
LoginForm.Show();
BuddyForm.Hide();
}
}
public class Form1 : Form
{
private Mediator _mediator;
public Form1(Mediator mediator)
{
_mediator = mediator;
}
protected virtual void Login_Click(object sender, EventArgs e)
{
_mediator.ShowBuddy();
}
}
public class Form2 : Form
{
private Mediator _mediator;
public Form2(Mediator mediator)
{
_mediator = mediator;
}
protected virtual void Logout_Click(object sender, EventArgs e)
{
_mediator.Logout();
}
}
|
|
|
|
|
Since you couldnt help here is how you do it declare a public, static variable of type Form1 just below the Form1 class declaration. I’ve named the variable frm1
public static Form1 frm1 = null;
then when you show form2
frm1 = this;
this.Visible = false;
Form2 frm2 = new Form2();
frm2.Show();
then from form2 you can call
Form1.frm1.show();
so thanks for all your help lol
|
|
|
|
|
|
Wow - that's some nasty ass code. Can I make a few suggestions:
1 - buy a beginners book before you become more entrenched in the really bad habits that you're currently forming. Otherwise, your code will always suck as much as this code does.
2 - try to use real variable names. form1 and form2 make sense on your first day of coding, they are not workable in a real project
Seriously, you come here, ask for help, complain when you get it, and then you're all proud because you found a way that frankly, belongs in the coding horrors forum.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
That's one seriously bad piece of code. Why do you think yours is better than the solution I posted above? Let's see - I've been in this industry over 20 years, and have extensive experience in developing applications including using patterns to develop robust systems - and you? Well you accept default form names. Nuff said.
|
|
|
|
|
But look how much code yours is. His is three lines or something, so it MUST be better.....
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for that - that really made me laugh, and I needed it.
|
|
|
|
|
Can any one tell me how to center align the items in the combo box? I've been reading quite a few forums but couldn't figure out any proper method.
I want both the list of items in the combo box and the selected item to be center aligned.
Thanks in advance.
Bala
|
|
|
|
|
Bala Thirumalai wrote: Can any one tell me how to center align the items in the combo box?
Using an alignment property if one exists would be the way. If it does not exist the you can do OwnerDraw.
led mike
|
|
|
|
|
they should have a text aling property
|
|
|
|
|
But I couldn't find any such text align property for the combo box. My exact requirement is to use a drop down list type combo box. I'll try Owner draw. Thanks!
modified on Friday, March 7, 2008 9:57 PM
|
|
|
|
|
Hi,
I want to find out how to use the "SecurityTrimmingEnabled="True"" on a Windows Form. I need to impliment Authentication and Authorization on a application and I need to hide/show controls based on a user(s) Role.
Can someone please tell me how to do this or give me advice as to find information on this?
Thanks!
Illegal Operation
Making Computer Software Talk
|
|
|
|
|
Illegal Operation wrote:
Can someone please tell me how to do this or give me advice as to find information on this?
I know absolutely nothing about this, it sounds like you know more than I do about it. If I wanted to know more I would try to find some documentation on the MSDN site.
led mike
|
|
|
|
|
You can't use this directly (a la the sitemap), so you would need to role your own. You could use the standard Membership/Role providers API - it is possible in a WinForms app; I've done it. Then you could use an ExtenderProvider to achieve this - I've written something along these lines here[^].
|
|
|
|
|
Anyone have any ideas how I could go about detecting any windows context menu while it's popping up?
Is there any message I can register for, that you may have heard about?
Just to be certain, I'm not trying to hook all context menus in my application, I'm trying to hook all menus globally.
www.wickedorange.com
www.andrewvos.com
modified on Friday, March 7, 2008 5:23 AM
|
|
|
|
|
I don't know whether it can be done or not but if it can I guess you will need global hooks.
|
|
|
|
|
Okay, SetWinEventHook does what I need.
Now I just need to get a handle to the context menu.
FindWindow("#32768", NULL) seems to get the temporary pointer assigned to the menu, not the actual HMENU.
Any ideas now?
www.wickedorange.com
www.andrewvos.com
|
|
|
|
|
|
why you repeat the post in multiple fourms
Yogesh Agarwal
|
|
|
|
|
Actually I was not sure where it will be appropriate to place it however I needed help as soon as possible
thus i placed i repeated the post to make sure that i get my answer
i am sorry if u mind it and thank u so much 4 ur kind help
Sadaf
|
|
|
|
|
Sadaf Naeem wrote: i am sorry if u mind it
It's not just him. It's an abuse of CodeProject resources and considered bad behavior for any member to do it.
Sadaf Naeem wrote: I needed help as soon as possible
So does everyone, you're not special? Try reading these posting guidelines[^].
led mike
|
|
|
|
|
Does anyone happen to know how to extend the limit of the RichTextBox of Visual Studio .Net
so i can open text files up to 4Gb. Can anyone point me in the right direction...
Thanks.
|
|
|
|
|
jazy1 wrote: Can anyone point me in the right direction...
Even if the system could do that it would be bad practice. The preferred method is to buffer the data in far smaller chunks in response to the user navigating through the file. Of course this is no small undertaking.
led mike
|
|
|
|
|
I guess so. Thanks for your reply...
|
|
|
|
|
Please help.. im having a difficulties to figure out this problem...
Is it possible to cancel or not to invoke the MyBase.Deactivate in vb windows Forms??
I have an application which starts up after the windows environment load in XP... and my application will automatically loads up.. and i need to make it stay the form active and has focus on it under the desktop windows environment.. for the first load it has the focus and of course the active form.. but i dont know what's happening after when my win application load? it lost its focus and its title bar above becomes deactivated and lost focus or not to be active form.. may be because there is still some windows services are still loading by the OS?... correct me if im wrong...
even though i've already removed all the auto-start up application in my pc except my application?
so what i need is a code in my winform application to make it sure that when the deactivation event is trigger? then it will just trigger again some functions or event function to re-activate my win application and stay active inside the desktop environment...
and ohhh.. reminders.. my application is accepting input from a barcode reader that's why i need to make it sure my application always got the focus.. because i assign a pc which has only one functionality, there's no other winforms application is running except my winforms, in such a reason...
here's my sample code thats won't work enough...
this code only just select the icon in the task bar but not to re-activate the whole winform and can accept input from the barcode reader..
*********************************
<br />
Private Sub MaskedTextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MaskedTextBox1.LostFocus<br />
Me.MaskedTextBox1.Focus()<br />
MaskedTextBox1.Select(0, Me.MaskedTextBox1.TextLength)<br />
'Me.MaskedTextBox1.SelectAll()<br />
End Sub<br />
<br />
Private Sub frmTimeLogger_Deactivate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate<br />
Try<br />
Me.Activate()<br />
Me.Focus()<br />
Me.MaskedTextBox1_LostFocus(sender,e)<br />
Catch ex As Exception<br />
MsgBox(ex.ToString())<br />
End Try<br />
End Sub<br />
***************************************
please anybody who have an idea about this?? please help...
thanks for kindness in advance...
modified on Tuesday, March 4, 2008 1:17 AM
|
|
|
|