Creating Winform program uses .net core3.0 official version

Recently been looking forward to the official version core3.0 .net out, that this version came out, Winform program ushered in a new life, but 9.23 Ri out immediately download updates VS, create a new .net core Winform project, found no Winform form Designer. Microsoft currently is by way of plug-ins, let alone download Winform designer, this design is still a preview version, many features still not achieved, can only be regarded as a simple prototype, this blog Case Study Based on .net core3.0 Creating a common WInform program that allows us to know the program based on .net core3.0 created probably look at.

1, the development environment ready

Based WInform development .net core3.0 do, you need to first update to your Visual Studio 16.3, this version is the integration of .net core3.0, and therefore able to develop basic .net core Winform program.

Followed download winforms-designer plug-in, this is the designer support for Winform form, so that we can interface design and development by dragging the control mode.

. NET Core Windows Forms visual designer in the future must be part of the future of Visual Studio 2019 updates, but for now, Visual Studio visual designer wants to expand, the need for a pre-release.

After these two steps, and other developers to create our common VS projects the same.

 

 After creating a project, we can open the corresponding Winform form, and you can see some Winform interface controls in the toolbox inside, good control is probably about the same as before, bad things are a lot less conventional Winform control, this is currently under development WInform Designer preview reason why it.

 

2. Create a program WInform

To create WInform a simple test program, we can add some fill WInform interface controls, but use of the process, found that many interface elements that do not provide the required support interface controls, including toolbars, properties which are not perfect, as ImageList objects and attributes support Image object, we may only be used by way of code.

I created a simple WInform interface, drag some conventional controls, but some controls require the use of images, such as ListView, PictureBox such as these, we need to (specify the image can not pass attribute to the way) by the code set

 

 

Finally, the interface display shown in the following effects.

 

 As shown in the following source code form.

   public  partial  class the Form1: Form1 
    { 
        public the Form1 () 
        { 
            the InitializeComponent (); 
        } 

        Private  void the button1_Click ( Object SENDER, EventArgs E) 
        { 
            MessageBox.Show ( " hello, this is a .net core of Winform program " , " message " , 
                MessageBoxButtons.OK, MessageBoxIcon.Information | MessageBoxIcon.Asterisk); 
        } 

           
        Private the imageList imageList = new new the imageList ();
         Private  void Form1_Load(object sender, EventArgs e)
        {
            var image = Image.FromFile(Path.Combine(Application.StartupPath, "SplashScreen.png"));
            if(image != null)
            {
                this.pictureBox1.Image = image;
            }

            imageList.Images.Clear();
            var iconPath = Path.Combine(Application.StartupPath, "icons");
            var fileNames = Directory.GetFiles(iconPath, "*.ico");
            foreach(string file in fileNames)
            {
                imageList.Images.Add(file, Image.FromFile(file));
            }
            this.treeView1.ImageList = imageList;
            foreach(TreeNode node in this.treeView1.Nodes)
            {
                SetNodeImage(node);
            }

            this.button1.Image = imageList.Images[2];
        }

        private void SetNodeImage(TreeNode node)
        {
            foreach (TreeNode subNode in node.Nodes)
            {
                subNode.ImageIndex = subNode.Level;
                subNode.SelectedImageIndex = subNode.Level;
                SetNodeImage(subNode);
            }
        }

We can see, .net WInform program under the core, it's a form element or related objects, naming inconsistency does not occur, it is still very easy to use the same, but a lot is the corresponding interface function, currently only through way to supplement the code behind, we can come to achieve a more complete effect, and .net framework framework has been very good sound Winform development, the gap really is not the slightest bit, it seems that the development of core winform .net road is still very long We need more support tool for the job level.

Interface program inside, we see the namespace lot less than before got them. Mainly based on .net WInform packet core offer.

We look at the files in the program directory as shown below.

 

Since we have not yet considered .net core level of third-party libraries, so there is no use third-party DLL, then after integration, third-party reference is also a very big problem head-related, if most commonly used class libraries are based on .net standard library support, that is quite good, otherwise it could face a dilemma, but the .net core of Winform development I think it is worth looking forward to, after all, introducing a whole .net core development roadmap, to enterprises or individuals, is a very good development scenarios.

 

Guess you like

Origin www.cnblogs.com/wuhuacong/p/11617175.html