Development of the catering system for winform loading and flash processing and moving of borderless forms

Source: Internet
Author: User

This article will mainly share with you the problems encountered during the development of the 'catering system' and will summarize the experiences of this project in the future, hoping to help you!

1. Flash processing of form loading-this problem may be applied to winform.ProgramProblems frequently encountered during development, but some forms flash problems are obvious and serious-at this time we can adopt optimization methods, such: compress the image size in the form (if an image is used in the form )..., however, we may try to optimize and find that the problem has not been greatly improved. The following describes how to solve the problem in this project:

-- Figure 1

-- Figure 2

The above two figures correspond to the following respectively: Log On (frmlogin) and the main form (using MDI, the main form is actually: frmmain (MDI container) + frmindex). frmlogin switches to the main form, if direct switching is performed, the main form will flash obviously during loading-because it is equivalent to loading and displaying both frmmain (MDI container) and frmindex forms at the same time, A large background image is used in the frmindex form. [Solution: When you want to switch to the main form in frmlogin, use timer to control-first set the main form to completely transparent, 1 S (timer time interval (the loading of the main form can be completed within the time interval), and then set the main form to opacity.CodeAs follows:

Code

  Private  Frmmain FRM  =     Null  ;

Private Void Picloginbox_click ( Object Sender, eventargs E)
{
Isshowloading ( True );
This . Picloginbox. Enabled = False ;
This . Lblloading. Text = " Loading System. Please wait... " ;
Timer_load.start ();
}

Private Void Timer_load_tick ( Object Sender, eventargs E)
{
Try
{
If (FRM ! = Null )
{
Timer_load.stop ();
This . Hide ();
FRM. Opacity = 1 ; // Set the normal display of the form
Isshowloading ( False );
}
Else
{
FRM = New Frmmain ();
FRM. Opacity = 0 ; // Set the form to completely transparent
FRM. Show ();
This . Topmost = True ;
}
}
Catch (Exception ex)
{
Handleerror (Ex );
}
}

2. move without border form -- paste code directly, demo can be downloaded from csdn: http://hutao123654.download.csdn.net/

Code

  Using  System;
Using System. Collections. Generic;
Using System. text;

Namespace Zhiyiform. codefile
{
Using System. Windows. forms;
Internal Class Formmove
{
Private Bool Ismousedown = False ;
Private System. Drawing. Point formlocation; // Form Location
Private System. Drawing. Point mouseoffset; // Mouse position
Private Form movedform = Null ;
Private Control conobj = Null ;

Private Formmove ()
{}

/// <Summary>
///
/// </Summary>
/// <Param name = "movedform"> Form to be moved </Param>
/// <Param name = "conobj"> Controls for controlling the movement of a form. If it is null, the form itself is used. </Param>
Public Formmove (Form movedform, control conobj)
{
This . Movedform = Movedform;
This . Conobj = (Conobj = Null ) ? Movedform: conobj;
This . Conobj. mousedown + = New Mouseeventhandler (conobj_mousedown );
This . Conobj. mousemove + = New Mouseeventhandler (conobj_mousemove );
This . Conobj. mouseup + = New Mouseeventhandler (conobj_mouseup );
}


Private Void Conobj_mousedown ( Object Sender, mouseeventargs E)
{
If (E. Button = Mousebuttons. Left)
{
Ismousedown = True ;
Formlocation = Movedform. location;
Mouseoffset = Control. mouseposition;
This . Conobj. cursor = System. Windows. Forms. cursors. sizeall;
}
}

Private Void Conobj_mouseup ( Object Sender, mouseeventargs E)
{
This . Conobj. cursor = System. Windows. Forms. cursors. default;
Ismousedown = False ;
}

Private Void Conobj_mousemove ( Object Sender, mouseeventargs E)
{
If (Ismousedown)
{
Int _ X = 0 ;
Int _ Y = 0 ;
System. Drawing. Point PT = Control. mouseposition;
_ X = Mouseoffset. x - PT. X;
_ Y = Mouseoffset. Y - PT. Y;

Movedform. Location = New System. Drawing. Point (formlocation. x - _ X, formlocation. Y - _ Y );
}
}
}
}

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.