Advertisement
kijato

c#_winforms_skeleton_v2.cs

Aug 31st, 2020
1,544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.52 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4.  
  5. /*
  6. set CSC=c:\Windows\Microsoft.NET\Framework64\v4.0.30319\
  7. set CSC=c:\Program Files (x86)\MSBuild\12.0\Bin\amd64\
  8. set CSC=c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\
  9. set path=%csc%;%path%
  10. csc.exe -debug+ -target:exe -r:System.Windows.Forms.dll,System.Drawing.dll -platform:x64 WindowsFormsSkeletonApplication.cs && WindowsFormsSkeletonApplication.exe
  11. c:\ProgramData\CS-Script\CSScriptNpp\1.7.24.0\Roslyn\csc.exe -debug- -target:exe -r:System.Windows.Forms.dll,System.Drawing.dll -platform:x64 WindowsFormsSkeletonApplication.cs
  12. */
  13.  
  14. namespace WindowsFormsSkeletonApplication
  15. {
  16.     class Program : Form
  17.     {
  18.  
  19.         MainMenu mm = new MainMenu();
  20.     MenuItem mi1;
  21.  
  22.         Panel p = new Panel();
  23.        
  24.     SplitContainer splitContainer = new SplitContainer();
  25.        
  26.         StatusBar sb = new StatusBar();
  27.         StatusBarPanel sbp1 = new StatusBarPanel();
  28.         StatusBarPanel sbp2 = new StatusBarPanel();
  29.  
  30.  
  31.         Form f = new Form();
  32.         ListBox listBox1 = new ListBox();
  33.         Label l = new Label();
  34.  
  35.  
  36.     [STAThread]
  37.         public static void Main(string[] args)
  38.         {
  39.             try
  40.             {
  41.                 //Application.SetHighDpiMode(HighDpiMode.SystemAware);
  42.                 Application.EnableVisualStyles();
  43.                 Application.Run(new Program());
  44.             }
  45.             catch (Exception e)
  46.             {
  47.                 Console.WriteLine(e.Message);
  48.             }
  49.  
  50.         }
  51.  
  52.         public Program()
  53.         {
  54.             this.Text = Application.StartupPath;
  55.             this.Font = new Font(FontFamily.GenericSansSerif, 10);
  56.  
  57.             mi1 = new MenuItem(text: "&File");
  58.         mm.MenuItems.Add(mi1);
  59.             MenuItem mi2 = new MenuItem("&Open");
  60.             mi2.Click += new EventHandler(mi2_Click);
  61.             mi1.MenuItems.Add(mi2);
  62.             mi1.MenuItems.Add(new MenuItem(text: "&Save", onClick: mi3_Click));
  63.             mi1.MenuItems.Add("----");
  64.             mi1.MenuItems.Add(new MenuItem(text: "&Exit", onClick: (sender, args) => Application.Exit()));
  65.             this.Menu = mm;
  66.  
  67.             sb.Panels.Add(sbp1);
  68.             sb.Panels.Add(sbp2);
  69.             sb.ShowPanels = true;
  70.             sb.Font = new Font(FontFamily.GenericSansSerif, this.Font.Size-2);
  71.             this.Controls.Add(sb);
  72.  
  73.             sbp1.Text = "-";
  74.             sbp1.AutoSize = StatusBarPanelAutoSize.Spring;
  75.             sbp2.Text = System.DateTime.Today.ToLongDateString();
  76.             sbp2.AutoSize = StatusBarPanelAutoSize.Contents;
  77.  
  78.             /*p.Location = new Point(5, 5);
  79.             p.Size = new Size( this.Width - 18 - 10, this.Height - sb.Height - 50 );
  80.             p.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
  81.             p.BackColor = Color.GhostWhite;
  82.             p.MouseMove += new MouseEventHandler(Panel_MouseMove);
  83.             this.Controls.Add(p);*/
  84.  
  85.         splitContainer.Location = new Point(3, 3);
  86.         splitContainer.Size = new Size( this.Width - 18 - 5, this.Height - sb.Height - 45 );
  87.         splitContainer.BorderStyle = BorderStyle.FixedSingle;
  88.         splitContainer.Anchor = ( AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right );
  89.         splitContainer.Panel1.BackColor = Color.FloralWhite;
  90.         splitContainer.Panel2.BackColor = Color.GhostWhite;
  91.         Controls.Add(splitContainer);
  92.         splitContainer.Panel1.MouseMove += new MouseEventHandler(Panel_MouseMove);
  93.  
  94.         }
  95.  
  96.         private void mi2_Click(object sender, EventArgs e)
  97.         {
  98.             MessageBox.Show( sender.ToString() + Environment.NewLine + Environment.NewLine + e.ToString() );
  99.         }
  100.  
  101.         private void mi3_Click(object sender, EventArgs e)
  102.         {
  103.             MessageBox.Show( this.Font.ToString() +"\n"+ sb.Font.ToString() );
  104.            
  105.         listBox1.Width = f.Width - 25;
  106.         listBox1.Location = new Point(5,5);
  107.         foreach ( FontFamily oneFontFamily in FontFamily.Families )
  108.         {
  109.             listBox1.Items.Add(oneFontFamily.Name);
  110.         }
  111.         listBox1.DoubleClick += new EventHandler(ListBox1_DoubleClick);
  112.         f.Controls.Add(listBox1);
  113.         l.Location = new Point(5,listBox1.Top + listBox1.Height +5);
  114.         f.Controls.Add(l);
  115.         f.Show();          
  116.            
  117.         }
  118.  
  119.         private void Panel_MouseMove(object sender, MouseEventArgs e)
  120.         {
  121.             sbp1.Text = e.X + " " + e.Y;
  122.         }
  123.  
  124.         private void ListBox1_DoubleClick(object sender, EventArgs e)
  125.         {
  126.             if (listBox1.SelectedItem != null)
  127.             {
  128.                  l.Text = listBox1.SelectedItem.ToString();
  129.             }
  130.         }
  131.        
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement