Skip to content

Commit

Permalink
add example with alternatives to messagebox
Browse files Browse the repository at this point in the history
  • Loading branch information
grantwinney committed Aug 16, 2023
1 parent 45cd11f commit a7301c7
Show file tree
Hide file tree
Showing 17 changed files with 1,203 additions and 0 deletions.
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.6.33801.468
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlternativesToMessageBox", "AlternativesToMessageBox\AlternativesToMessageBox.csproj", "{BA333124-25C4-4982-BFE6-BABD9A016E18}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BA333124-25C4-4982-BFE6-BABD9A016E18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA333124-25C4-4982-BFE6-BABD9A016E18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA333124-25C4-4982-BFE6-BABD9A016E18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA333124-25C4-4982-BFE6-BABD9A016E18}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {947C4C2A-34D6-4BDA-B6A0-197DA835AB1B}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BA333124-25C4-4982-BFE6-BABD9A016E18}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>AlternativesToMessageBox</RootNamespace>
<AssemblyName>AlternativesToMessageBox</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="frmMessages.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmMessages.Designer.cs">
<DependentUpon>frmMessages.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmMessages.resx">
<DependentUpon>frmMessages.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\7830804_programming_flag_icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AlternativesToMessageBox
{
public partial class Form1 : Form
{
const string MSG_CAPTION = "Really important message";
const string MSG_TEXT = "HALT! Read this important message!";

frmMessages msgForm;

public Form1()
{
InitializeComponent();
toolStripStatusLabelMessage.Text = "";
}


// MessageBox (for the traditionalist)

private void btnUseMessageBox_Click(object sender, EventArgs e)
{
MessageBox.Show(MSG_TEXT, MSG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}


// NotifyIcon aka Windows notification area (when in Rome...)

private void btnUseNotifyIcon_Click(object sender, EventArgs e)
{
notifyIcon1.ShowBalloonTip(2000, MSG_CAPTION, $"{MSG_TEXT} ({DateTime.Now:h:mm:ss tt})", ToolTipIcon.Warning);
}


// StatusStrip (did you remember this exists?)

readonly Queue<string> pendingMessages = new Queue<string>();

private void btnUseStatusStrip_Click(object sender, EventArgs e)
{
pendingMessages.Enqueue($"{DateTime.Now:h:mm:ss.fff tt}: {MSG_TEXT}");
}

private async void timer1_Tick(object sender, EventArgs e)
{
timer1.Stop();

while (pendingMessages.Count > 0)
{
toolStripStatusLabelMessage.Text = pendingMessages.Dequeue();
await Task.Delay(3000);
}

toolStripStatusLabelMessage.Text = "";
timer1.Start();
}


// FlowLayoutPanel (okay, no one remembers this exists)

private async void btnUseFlowLayoutPanel_Click(object sender, EventArgs e)
{
await AddMessageToPanel($"{DateTime.Now:h:mm:ss.fff tt}: {MSG_TEXT}");
}

private async Task AddMessageToPanel(string message)
{
var l = new Label { Text = message, AutoSize = true };
flowLayoutPanelMessages.Controls.Add(l);
await Task.Delay(3000); // give user a few seconds to read it
l.Dispose();
}


// A separate Form (hey why not)

private void btnUseSeparateForm_Click(object sender, EventArgs e)
{
if (msgForm == null)
{
msgForm = new frmMessages();
msgForm.Show();
}

frmMessages.Messages.Enqueue($"{DateTime.Now:h:mm:ss.fff tt}: {MSG_TEXT}");
}
}
}
Loading

0 comments on commit a7301c7

Please sign in to comment.