C # developing Windows program Tips

Source: Internet
Author: User
window| Program | tips

1. An application can only be opened once by the user
Process Mobj_pro =process.getcurrentprocess ();
Process[] Mobj_prolist=process.getprocessesbyname (Mobj_pro. ProcessName);
if (mobj_prolist.length>1)
{
MessageBox.Show ("The current application is open!") "," System hints ", MessageBoxButtons.OK, Messageboxicon.exclamation, Messageboxdefaultbutton.button1);
Return
}
2. Only one child window opens under a frame window
Customeradd Pobj_customeradd;
Form pobj_customeradd_return=checkisexit ("Customeradd");
if (pobj_customeradd_return==null)
{
Pobj_customeradd=new Customeradd ();
Opensheet (Pobj_customeradd);
}
Else
{
Opensheet ((Customeradd) pobj_customeradd_return);
}
void Opensheet (Form pobj_form)
{
Pobj_form. Mdiparent=this;
Pobj_form. Show ();
}

/**////<summary>
To determine whether a window exists
</summary>
<param name= "ps_windowname" > Window name </param>
<returns> existence returns the instance of this window does not exist return null</returns>
Form checkisexit (String ps_windowname)
{
for (int i=0;i<this. mdichildren.length;i++)
{
if (this. Mdichildren[i]. Name==ps_windowname)
{
return this. Mdichildren[i];
}
}
return null;
}
3. pop-up window to show the gradient effect
Add a Timer control to the page Fadetimer,interval set to 50
Class has an instance variable of
Private m_showing=true;
Write in Form_Load:
Opacity = 0.0;
Activate ();
Refresh ();
Fadetimer.start ();
Refresh (); Write in the Tick event of the timer control:

if (m_showing)
{
Double d = 1000.0/fadetimer.interval/100.0;
if (Opacity + D >= 1.0)
{
Opacity = 1.0;
Fadetimer.stop ();
}
Else
{
Opacity = D;
}
}
Else
{
Double d = 1000.0/fadetimer.interval/100.0;
if (opacity-d <= 0.0)
{
Opacity = 0.0;
Fadetimer.stop ();
}
Else
{
Opacity-= D;
}
}
4. In the control textbox, the function of pressing ENTER is equivalent to the TAB key
public class Ostextbox:textbox
{
Public Ostextbox ()
{

}

BOOL Mb_iskeyenter=true;

[
Category ("Data"),
DefaultValue (True),
Mergableproperty (False)
]
public bool Iskeyenter
{
Get
{
return mb_iskeyenter;
}
Set
{
Mb_iskeyenter=value;
}
}

protected override void OnKeyPress (KeyPressEventArgs e)
{
Base. OnKeyPress (e);
if (Mb_iskeyenter)
{
if (E.keychar = = (char) keys.enter)
{
Sendkeys.send ("{tab}");
}
}
}

}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.