oktatas:programozas:csharp:dotnetcore:windows_forms
< .Net Core
Projekt létrehozása
Linuxon .Net Core 7.0 esetén nem működik.
dotnet new winforms
A projekt
- Program.cs
namespace app01;
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
- Form1.cs
namespace app03;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
- Form1.Designer.cs
namespace app03;
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
- app01.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
- app01.csproj.user
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Update="Form1.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>
Gomb
- Form1.cs
namespace app01;
public partial calss Form1 : Form {
Button button = new Button();
public Form1() {
button.Text = "Mehet";
button.Location = new Point(50, 50);
button.Click += new EventHandler(Button_Click);
this.Controls.Add(button);
this.Width = 400;
this.Height = 300;
this.Show();
}
private void Button_Click(object? sender, EventArgs e) {
MessageBox.Show("Működik");
}
}
oktatas/programozas/csharp/dotnetcore/windows_forms.txt · Utolsó módosítás: 2024/03/07 21:14 szerkesztette: admin