Added missing source file for placeholder tool strip text box

This commit is contained in:
biwa 2021-12-14 18:19:47 +01:00
parent a5df323717
commit 54b99ee710
2 changed files with 80 additions and 0 deletions

View file

@ -184,6 +184,9 @@
<DependentUpon>ExternalCommandControl.cs</DependentUpon>
</Compile>
<Compile Include="Controls\FolderSelectDialog.cs" />
<Compile Include="Controls\PlaceholderToolStripTextBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\Scripting\TextEditorControl.cs" />
<Compile Include="Controls\TransparentTrackBar.cs">
<SubType>Component</SubType>

View file

@ -0,0 +1,77 @@
#region ================== Namespaces
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
#endregion
namespace CodeImp.DoomBuilder.Controls
{
// This is based on https://stackoverflow.com/questions/50918225/how-to-add-placeholder-text-to-toolstriptextbox
[ToolboxBitmap(typeof(ToolStripTextBox))]
public class PlaceholderToolStripTextBox : ToolStripTextBox
{
#region ================== DLL Imports
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int msg, int wParam, string lParam);
#endregion
#region ================== Constants
private const int EM_SETCUEBANNER = 0x1501;
#endregion
#region ================== Variables
private string placeholder;
#endregion
#region ================== Properties
public string PlaceholderText
{
get { return placeholder; }
set
{
placeholder = value;
UpdatePlaceholderText();
}
}
#endregion
#region ================== Constructors
public PlaceholderToolStripTextBox()
{
Control.HandleCreated += Control_HandleCreated;
}
#endregion
#region ================== Events
private void Control_HandleCreated(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(placeholder))
UpdatePlaceholderText();
}
#endregion
#region ================== Methods
private void UpdatePlaceholderText()
{
SendMessage(Control.Handle, EM_SETCUEBANNER, 0, placeholder);
}
#endregion
}
}