IT Community - Software Programming, Web Development and Technical Support

Pratical issues in adding controls to Windows Forms in C#.Net 2005

This is a discussion on Pratical issues in adding controls to Windows Forms in C#.Net 2005 within the C# Programming forums, part of the Software Development category; Hi all, Here in this thread,we can discuss the practical issues in adding the controls to the windows forms ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-22-2007, 01:49 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi all,
Here in this thread,we can discuss the practical issues in adding the controls to the windows forms in VS 2005.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-22-2007, 01:52 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Exclamation Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

HI Sathish,
How can I add items to the System Menu of a form in VS 2005?Can anyone help me?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-22-2007, 02:51 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

To do this, you can use use iterop to access the GetSystemMenu and AppendMenu Win32 APIs. You also need to override the form's WndProc method to catch and act on the menu message. This idea was posted in the Microsoft newsgroups by Lion Shi.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-22-2007, 02:53 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Exclamation Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Sathish,
Well said.Its working.How can I have a form with no title bar, but yet keep the resizing borders?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-22-2007, 02:55 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Deeban,
Well.Set your form's Text and ControlBox properties.

myForm.Text = "";
myForm.ControlBox = false;
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 09-22-2007, 02:58 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Exclamation Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi sathish,
I don't want to have the Close box on my form's title bar. How do I remove this system menu box?Any idea?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-22-2007, 02:59 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi,
Its very simple.Set the property Form.ControlBox to false.Thats it.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 09-22-2007, 03:01 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Exclamation Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Sathish,
How do I change my application's icon?Any idea?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 09-22-2007, 03:03 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi,
In the Solution Explorer window, you'll see a file called app.ico in your project. This file contains your application icon. You can change this to a different file in the project properties screen which you see by right-clicking the project node in the Solution Explorer, and selecting Properties..
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 09-22-2007, 03:06 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Exclamation Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Sathish,
Good going. How can I tell if a form is closed from the controlbox (system menu) or from a call to Form.Close?can you tell me?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 09-22-2007, 03:10 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Deeban,
One way to do this is to override the form's WndProc method and check for WM_SYSCOMMAND and SC_CLOSE. Looking for WM_CLOSE in the override is not sufficient as WM_CLOSE is seen in both cases. A sample is available for download (C#, VB).
public const int SC_CLOSE = 0xF060;
public const int WM_SYSCOMMAND = 0x0112;
//_closeClick is a bool member of the form initially set false...

// It can be tested in the Closing event to see how the closing came about.

protected override void WndProc(ref System.Windows.Forms.Message m)
{
if(m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE)

this._closeClick = true;
base.WndProc(ref m);
}
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 09-22-2007, 03:14 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Exclamation Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Sathish,
I have two forms. I want to access a textbox on one form from the other form?How can I do it?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 09-22-2007, 03:16 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Sathish,
One way to do this is to make the TextBox either a public property or a public field. Then you will be able to access it through the instance of its parent form. So, if TextBox1 is a public member of FormA and myFormA is an instance of FormA, then you can use code such as

[VB.NET]

Dim strValue as String = myFormA.TextBox1.Text
[C#]

string strValue = myFormA.TextBox1.Text;

anywhere myFormA is known. Here is a VB project illustrating this technique.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 09-22-2007, 03:18 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Exclamation Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Sathish,
How do I create a non-modal top level form that always stays on top of all the app's windows (like the VS.Net find dialog)?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 09-22-2007, 03:21 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Deeban,
Thats a good question.Now let me tell you the answer.Make your main form the "Owner" of the form in question. Refer to Form.Owner in class reference for more information.

[C#]

findReplaceDialog.Owner = this; // Your main form.

findReplaceDialog.TopLevel = false;

[VB.Net]

findReplaceDialog.Owner = Me ' Your main form.

findReplaceDialog.TopLevel = False
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 09-22-2007, 03:22 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Exclamation Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi ,
How can I display a form that is 'TopMost' for only my application, but not other applications?
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 09-22-2007, 03:25 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Thumbs up Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Sathish,
Sorry I dont know sathish.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 09-22-2007, 03:47 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Deeban,
Its ok,I have found the solution.
We can do this by setting the child form's TopMost to False and setting its Owner property to the Main Form.

[C#]

Form1 f = new Form1();
f.TopMost = false;
f.Owner = this;
f.Show();

[VB.NET]

dim f as New Form1()
f.TopMost = False
f.Owner = Me
f.Show()
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 09-22-2007, 04:34 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Deeban
The framework automatically resizes the form if the current Font size during runtime is different from the font size in design-time. It however doesn't auto size when the resolution changes. But it should be easy for you to accomplish. You could derive a custom Form, provide a "ScreenResolutionBase" property that could return the current screen resolution (Screen.PrimarScreen.Bounds will give you this). This value will get serialized in code during design time. Then during runtime in the Form's OnLoad you could check for the current screen resolution and resize the Form appropriately.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20 (permalink)  
Old 09-22-2007, 04:50 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Exclamation Re: Pratical issues in adding controls to Windows Forms in C#.Net 2005

Hi Sathish,
How can I restrict or control the size of my form?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL 2005 Installation issues Error (0xc0000005). nnraja Server Management 2 10-29-2007 01:05 AM
Windows Forms Patterns Mramesh C# Programming 0 09-25-2007 09:13 AM
Windows Forms from MFC Sundaram C# Programming 5 09-25-2007 09:09 AM
Windows Forms Mouse Handling Sundaram C# Programming 3 09-25-2007 08:51 AM
Practical issues when we develop code in Windows Forms in C#.Net 2005 Sathish Kumar C# Programming 10 09-20-2007 07:17 AM


All times are GMT -7. The time now is 10:37 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0