Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Button #15

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions RunningButton/RunningButton.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RunningButton", "RunningButton\RunningButton.csproj", "{6DED2831-56E2-46F4-A1E4-DD55C9753BD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6DED2831-56E2-46F4-A1E4-DD55C9753BD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6DED2831-56E2-46F4-A1E4-DD55C9753BD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DED2831-56E2-46F4-A1E4-DD55C9753BD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DED2831-56E2-46F4-A1E4-DD55C9753BD4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E4705B43-4F95-4106-8FF0-4C71759317BC}
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions RunningButton/RunningButton/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace RunningButton
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
if (!System.OperatingSystem.IsWindows())
{
Console.WriteLine("Program is only supported on Windows");
System.Environment.Exit(0);
}
ApplicationConfiguration.Initialize();
Application.Run(new RunningButtonForm());
}
}
}
12 changes: 12 additions & 0 deletions RunningButton/RunningButton/RunningButton.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
67 changes: 67 additions & 0 deletions RunningButton/RunningButton/RunningButtonForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
namespace RunningButton

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Используйте file-scoped namespaces

{
public class RunningButtonForm: Form

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо комментарии

{
private Button button;
Random random;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо модификатор видимости и пустые строки между членами класса

public RunningButtonForm()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1000, 600);
this.Text = "Running Button";
this.button = new Button();
this.Controls.Add(button);
button.Text = "Press me";
button.Location = new Point(450, 275);
button.Size = new Size(100, 50);
button.MouseEnter += new System.EventHandler(this.Mouse_Hover);

Check warning on line 18 in RunningButton/RunningButton/RunningButtonForm.cs

View workflow job for this annotation

GitHub Actions / build-Windows

Nullability of reference types in type of parameter 'sender' of 'void RunningButtonForm.Mouse_Hover(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).

Check warning on line 18 in RunningButton/RunningButton/RunningButtonForm.cs

View workflow job for this annotation

GitHub Actions / build-Windows

Nullability of reference types in type of parameter 'sender' of 'void RunningButtonForm.Mouse_Hover(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).

Check warning on line 18 in RunningButton/RunningButton/RunningButtonForm.cs

View workflow job for this annotation

GitHub Actions / build-Windows

Nullability of reference types in type of parameter 'sender' of 'void RunningButtonForm.Mouse_Hover(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).

Check warning on line 18 in RunningButton/RunningButton/RunningButtonForm.cs

View workflow job for this annotation

GitHub Actions / build-Windows

Nullability of reference types in type of parameter 'sender' of 'void RunningButtonForm.Mouse_Hover(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).
button.Click += new System.EventHandler(this.Mouse_Click);

Check warning on line 19 in RunningButton/RunningButton/RunningButtonForm.cs

View workflow job for this annotation

GitHub Actions / build-Windows

Nullability of reference types in type of parameter 'sender' of 'void RunningButtonForm.Mouse_Click(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).

Check warning on line 19 in RunningButton/RunningButton/RunningButtonForm.cs

View workflow job for this annotation

GitHub Actions / build-Windows

Nullability of reference types in type of parameter 'sender' of 'void RunningButtonForm.Mouse_Click(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).

Check warning on line 19 in RunningButton/RunningButton/RunningButtonForm.cs

View workflow job for this annotation

GitHub Actions / build-Windows

Nullability of reference types in type of parameter 'sender' of 'void RunningButtonForm.Mouse_Click(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).

Check warning on line 19 in RunningButton/RunningButton/RunningButtonForm.cs

View workflow job for this annotation

GitHub Actions / build-Windows

Nullability of reference types in type of parameter 'sender' of 'void RunningButtonForm.Mouse_Click(object sender, EventArgs e)' doesn't match the target delegate 'EventHandler' (possibly because of nullability attributes).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullability-анализ ругается, стоило бы поправить

random = new Random();
this.MinimumSize = new Size(500, 500);
}
/// <summary>
Comment on lines +22 to +23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут надо пустую строку

/// 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);
}

/// <summary>
/// Event that happens when user hovers on the button
/// </summary>
/// <param name="sender">parameter that contains a reference to the control that raised the event</param>
/// <param name="e">parameter that contains the event data</param>
private void Mouse_Hover(object sender, EventArgs e)
{
this.button.Location = new Point(random.Next(0, this.Width - 130), random.Next(0 , this.Height - 100));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Никак не проверяется, что кнопка не оказалась прямо под курсором, так что на неё всё-таки можно кликнуть

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Используйте expression-bodied-методы везде, где только можно :)


/// <summary>
/// Event that happens when user successfully clicks the button
/// </summary>
/// <param name="sender">parameter that contains a reference to the control that raised the event</param>
/// <param name="e">parameter that contains the event data</param>
private void Mouse_Click(object sender, EventArgs e)
{
System.Windows.Forms.Application.Exit();
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
Comment on lines +61 to +64

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это какой-то кусок из сгенерённого файла


}
}