-
Notifications
You must be signed in to change notification settings - Fork 1
Home
This project should not be a substitute for System.Windows.Forms.
Microsoft has begun to implement System.Windows.Forms in NETCore with the introduction of NETCore 3.0-Preview. In older versions this was not the case. Since NETCore 3 is still a preview, you can at least create basic windows with this project. Due to its strong resemblance to System.Windows.Forms, the familiarization phase should be very short.
This project is intended for the Windows platform only. An implementation on Linux or Mac is not planned (provided). There are other projects that implement this.
Nevertheless, I believe that this project is sufficient for smaller applications.
Create a new Class derive from NativeWindow
//Native Window
public class Window1:NativeWindow
{
//Add your Controls
//in this example a Button
private NativeButton _Button;
//Override InitControls Function
protected override void InitControls()
{
//Set the properties of the Form.
this.Text = "Dies ist meine Anwnedung";//Caption of the Window.
this.Name = "Window1";
this.Left = 100;
this.Top = 100;
this.Width = 600;
this.Height = 400;
//Create the Button
this._Button = new NativeButton
{
Left = 10,
Top = 10,
Width = 100,
Height = 30,
Text = "Test",//Caption of the Button
Name = "bnTest",
Font = new Font(){Name="Arial",Size=14}
};
//Add Eventhandler
this._Button.Clicked += button_OnClicked;
//Add the Button to the Window.
this.Controls.Add(this._Button);
}
//Eventhandler for the Button
private void button_OnClicked(object sender, EventArgs e)
{
//Show a Messagebox.
MessageBox.Show("Button Clicked!");
}
}
To initilize the Application you have to create 2 Lines of Code in the Main-Function. This is necessary because of Threading and Windows Messaging.
using CoreWindowsWrapper;
namespace ConsleCaller
{
class Program
{
static void Main(string[] args)
{
//Create the Window
Window1 nw = new Window1();
//Run the Application
NativeApp.Run(nw);
}
}
}
The class Color Tools includes predefined colors, as well as the function RGB. Here you can modify the background color of the window. Unfortunately, it is currently not possible to change the background color of all controls.
// use the Defined Colors
this.BackColor = ColorTool.LightGray;
// use the RGB Function
this.BackColor = ColorTool.RGB(125,125,125);
The NativeWindow object has a property Menu. Here is the first entry of the menu deposited. The following example creates a File menu. This menu has 3 items and a separator entries. Open, Close, Separator and Exit.
//Creating the File Menu
NativeMenu menuFile = new NativeMenu("mnuFile", "&File");
//Create Sub-Items for File-Menu
NativeMenuItem menuFileOpen = new NativeMenuItem("mnuOpen", "&Open");
NativeMenuItem menuFileClose = new NativeMenuItem("mnuClose", "&Close Document");
NativeMenuItem menuFileSep = new NativeMenuItem("mnuFileSep") {IsSeparator = true};
NativeMenuItem menFileExit = new NativeMenuItem("mnuExit", "E&xit");
//Add Menu Event Handlers
menuFileClose.Click += FileClose_Click;
menuFileOpen.Click += FileOpen_Click;
menFileExit.Click += Menu_Exit;
//Add The Sub-Items to File-Menu
menuFile.Items.Add(menuFileOpen);
menuFile.Items.Add(menuFileClose);
menuFile.Items.Add(menuFileSep);
menuFile.Items.Add(menFileExit);
//Add the first Element of the Menu to the Form
this.Menu = menuFile;
If you want to continue to add main menus next to the File menu, create another NativeMenu class and add it to the Items listing in the File menu. Each menu entry below the new menu is added to this new menu.
//Create Help-Menu
NativeMenu menuHelp = new NativeMenu("&Help");
//Add Sub-Item to Help-Menu
NativeMenuItem menuInfo = new NativeMenuItem("&Info");
//Add Event-Handler
menuInfo.Click += MenuInfo_Click;
//Add the Sub-Item to the Help-Menu
menuHelp.Items.Add(menuInfo);
//Add the Help-Menu to the File-Menu
menuFile.Items.Add(menuHelp);
//Add the first Element of the Menu to the Form
this.Menu = menuFile;