WinForm & DEV knowledge summary, winfrom
--------------------------------------------------------------------------------
1. Code for calling the subform Form2 in the parent form Form1:
Form2 fr = new Form2();this.hide();fr.ShowDialog(this);
2. The FormClosed Event code of the subform:
private void Form2_FormClosed(object sender, FormClosedEventArgs e){Login login = (Login)this.Owner;login.Dispose();login.Close();}
--------------------------------------------------------------------------------
Winform drag form without Borders
private Point mPoint = new Point(); private void Form1_MouseDown(object sender, MouseEventArgs e){mPoint.X = e.X;mPoint.Y = e.Y;} private void Form1_MouseMove(object sender, MouseEventArgs e){if (e.Button == MouseButtons.Left){Point myPosittion = MousePosition;myPosittion.Offset(-mPoint.X, -mPoint.Y);Location = myPosittion;}}
--------------------------------------------------------------------------------
Methods for reading datatable
1, for (int I = 0; I <dt. rows. count; I ++) {string strname = dt. rows [I] ["field name"]. tostring ();} 2, foreach (datarow myrow in mydataset. tables ["temp"]. rows) {var str = myrow [0]. tostring ();} 3, foreach (datarow dr in dt. rows) {object value = dr ["columnsname"];} 4, Datatable. select ("kymd> '2017-11-5 'or kymd is null ")
----------------------------------------------------------------------------------
Datatable merge
// Premise: dt1 and dt2 tables have the same structure as foreach (DataRow dr in dt2.Rows) dt1.Rows. add (dr. itemArray); // bind the table maid = dt1; ------------------------------------------------------------------------------------ modify the column name MyDt in the able. columns ["xx"]. columnName = "aa ";
----------------------------------------------------------------------------------
Use dictionary to write key-value pairs and add them to the able to bind the combox display value and attribute value.
// Initialize the value of Dictionary <string, string> dic = new Dictionary <string, string> (); dic. add ("pressure", "AIRP"); dic. add ("temperature", "ATMP"); dic. add ("humidity", "RHU"); dic. add ("precipitation", "ACCP"); dic. add ("Wind Speed", "WIN"); dic. add ("Rizhao", "SSD"); dic. add ("ground temperature", "GST"); dic. add ("evaporation", "ACCE"); DataTable dt = new DataTable (); dt. columns. add ("key"); dt. columns. add ("name"); foreach (var item in dic) {DataRow dr = dt. newRow (); dr ["key"] = item. key; dr ["name"] = item. value; dt. rows. add (dr);} this. cmbType. dataSource = dt; this. cmbType. displayMember = "key"; this. cmbType. valueMember = "name ";
----------------------------------------------------------------------------------
Dev
1. How to Solve the Problem of selecting a record in the entire row
View-> OptionsBehavior-> EditorShowMode: Click
4. How to Make rows select but not edit (or edit a cell)
(1) View-> OptionsBehavior-> EditorShowMode: Click
(2) View-> OptionsBehavior-> Editable: false
5. How to disable the right-click column in GridControl
Set Run Design-> OptionsMenu-> EnableColumnMenu to: false
6. How to hide the GroupPanel header of GridControl
Set Run Design-> OptionsView-> ShowGroupPanel to: false
----------------------------------------------------------------------------------
Winfrom interaction with flash
// Obtain the Custom Event axShockwaveFlash1.FlashCall + = new AxShockwaveFlashObjects. _ outputs (axShockwaveFlash1_FlashCall); // The public void axShockwaveFlash1_FlashCall (object sender, AxShockwaveFlashObjects. _ IShockwaveFlashEvents_FlashCallEvent e) {XmlDocument document = new XmlDocument (); document. loadXml (e. request); XmlAttributeCollection attributes = document. firstChild. attributes; string command = attributes. item (0 ). innerText; MessageBox. show (command );}
----------------------------------------------------------------------------------
Set global skin for WinForm
// Set skin global string path = Application. startupPath + @ "\ skin \ Warm \ WarmColor3.ssk"; se = new Sunisoft. irisSkin. skinEngine (); se. skinAllForm = true; se. skinFile = path; this. startPosition = FormStartPosition. centerScreen;
Modify the interface icon
string iconPath = Application.StartupPath + @"\image\a.ico";this.Icon = new Icon(iconPath);
----------------------------------------------------------------------------------
Fade-in and fade-out effect of Winform
(From Baidu)
[System. runtime. interopServices. dllImport ("user32.dll")] private static extern bool AnimateWindow (IntPtr whnd, int dwtime, int dwflag); // The value of dwflag is public const Int32 AW_HOR_POSITIVE = 0x00000001; // public const Int32 AW_HOR_NEGATIVE = 0x00000002 is displayed from left to right; // public const Int32 AW_VER_POSITIVE = 0x00000004 is displayed from right to left; // public const Int32 AW_VER_NEGATIVE = 0x00000008 is displayed from top to bottom; // public const Int32 AW_CENTER = is displayed from bottom to top 0x00000010; // If the AW_HIDE flag is used, the window overlaps inward, that is, the window is shrunk; otherwise, the window is extended outward, that is, the window is expanded public const Int32 AW_HIDE = 0x00010000; // hide the window. By default, the window public const Int32 AW_ACTIVATE = 0x00020000 is displayed. // The activation window is displayed. Public const Int32 AW_SLIDE = 0x00040000 cannot be used after the AW_HIDE flag is used; // use the slide type. The default value is the scroll animation type. When the AW_CENTER flag is used, this flag is ignored public const Int32 AW_BLEND = 0x00080000; // transparency from high to low private void MainFM_Load (object sender, EventArgs e) {// fade-in effect AnimateWindow (this. handle, 3000, AW_BLEND | AW_ACTIVATE);} private void MainFM_FormClosing (object sender, FormClosingEventArgs e) {// fade out the AnimateWindow (this. handle, 3000, AW_BLEND | AW_HIDE );}
----------------------------------------------------------------------------------
GridControl in Dev
Fixed a column always displayed
BandedGridView view = advBandedGridView1 as AdvBandedGridView; GridBand bindSTCD = view. Bands. AddBand ("site information"); bindSTCD. Fixed = FixedStyle. Left;
Set the Fixed attribute of a column to Left.
----------------------------------------------------------------------------------
Retain decimal places
String result = String. Format ("{0: N2}", 0.55555); // a few digits of N
Note: The variable that must be followed by a number cannot be a string or another string.
----------------------------------------------------------------------------------
DateTime display time
This. xxx. DateTime = New DateTime (maid, 1 );
----------------------------------------------------------------------------------
Obtain the names of all objects in the folder.
string btopPath = Application.StartupPath + @"\SaveData\BTOP";DirectoryInfo mydir = new DirectoryInfo(btopPath);foreach (FileInfo item in mydir.GetFiles()){MessageBox.Show(item.FullName);}
----------------------------------------------------------------------------------
Traverse all files in the folder and read three rows. Matching xxxxxxxxxx is a number.
private static void LoadTime(int time1, int time2){string btopPath = Application.StartupPath + @"\SaveData\BTOP";DirectoryInfo mydir = new DirectoryInfo(btopPath);string data = ""; foreach (FileInfo item in mydir.GetFiles()){using (StreamReader sr = new StreamReader(item.FullName)){for (int i = 0; i < 3; i++){data += sr.ReadLine() + " ";}string rege = @"\d{10}";bool b = true;foreach (Match mm in Regex.Matches(data, rege, RegexOptions.IgnoreCase)){ if (b == true){b = false;time1 = int.Parse(mm.Value);time1 = int.Parse(time1.ToString().Substring(0, 4));}else{time2 = int.Parse(mm.Value);time2 = int.Parse(time2.ToString().Substring(0, 4));}
}
}
// MessageBox. Show (mydir. FullName );
}
}
Winform Packaging
You only need to run the exe file with the DLL you call. There are such ready-made exe tools on the Internet
Winform Packaging
You only need to run the exe file with the DLL you call. There are such ready-made exe tools on the Internet