This commit is contained in:
parent
63fd25601e
commit
bf25814d5b
61
PROMS/DropDownPanel/Controls/DropDownPanel.Designer.cs
generated
Normal file
61
PROMS/DropDownPanel/Controls/DropDownPanel.Designer.cs
generated
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
namespace AT.STO.UI.Win
|
||||||
|
{
|
||||||
|
partial class DropDownPanel
|
||||||
|
{
|
||||||
|
/// <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 Component 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.combo = new System.Windows.Forms.ComboBox();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// combo
|
||||||
|
//
|
||||||
|
this.combo.DropDownHeight = 1;
|
||||||
|
this.combo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.combo.FormattingEnabled = true;
|
||||||
|
this.combo.IntegralHeight = false;
|
||||||
|
this.combo.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.combo.Name = "combo";
|
||||||
|
this.combo.Size = new System.Drawing.Size(86, 21);
|
||||||
|
this.combo.TabIndex = 0;
|
||||||
|
this.combo.DropDown += new System.EventHandler(this.Combo_DropDown);
|
||||||
|
//
|
||||||
|
// DropDownPanel
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.Controls.Add(this.combo);
|
||||||
|
this.Name = "DropDownPanel";
|
||||||
|
this.Size = new System.Drawing.Size(105, 32);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.ComboBox combo;
|
||||||
|
}
|
||||||
|
}
|
287
PROMS/DropDownPanel/Controls/DropDownPanel.cs
Normal file
287
PROMS/DropDownPanel/Controls/DropDownPanel.cs
Normal file
@ -0,0 +1,287 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AT.STO.UI.Win
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Control that allows any other control that implements IDropDownAware to be displayed
|
||||||
|
/// in it's own combo-like dropdown area. This Control tries to mimic the standard ComboBox
|
||||||
|
/// as accurately as possible.
|
||||||
|
/// </summary>
|
||||||
|
public partial class DropDownPanel : UserControl, IDropDownAware
|
||||||
|
{
|
||||||
|
#region Private Variable Declarations
|
||||||
|
private IDropDownAware _dropDownControl = null;
|
||||||
|
private DropDownWindowHelper _dropDownHelper = null;
|
||||||
|
private Form _owner = null;
|
||||||
|
#endregion
|
||||||
|
#region Constructor / Destructor
|
||||||
|
/// <summary>
|
||||||
|
/// Default constructor
|
||||||
|
/// </summary>
|
||||||
|
public DropDownPanel()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
_dropDownHelper = new DropDownWindowHelper();
|
||||||
|
|
||||||
|
_dropDownHelper.DropDownClosed += new DropDownClosedEventHandler(DropDownHelper_DropDownClosed);
|
||||||
|
_dropDownHelper.DropDownCancel += new DropDownCancelEventHandler(DropDownHelper_DropDownCancel);
|
||||||
|
|
||||||
|
combo.DisplayMember = "Text";
|
||||||
|
combo.ValueMember = "Id";
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Control Events
|
||||||
|
/// <summary>
|
||||||
|
/// The owning form is set within this event, wich is required to
|
||||||
|
/// force the owning form not to loose focus when the dropdown is
|
||||||
|
/// being displayed. Inherited controls should provide the PopupControl
|
||||||
|
/// within an overridden implementation of this event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
protected override void OnHandleCreated(EventArgs e)
|
||||||
|
{
|
||||||
|
_owner = this.FindForm();
|
||||||
|
_dropDownHelper.ReleaseHandle();
|
||||||
|
|
||||||
|
if (_owner != null)
|
||||||
|
{
|
||||||
|
_dropDownHelper.AssignHandle(_owner.Handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make sure that the overall control's height is exactly the height
|
||||||
|
/// of the internal ComboBox and that the ComboBox's widt is exactly the
|
||||||
|
/// width of the control.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
protected override void OnResize(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnResize(e);
|
||||||
|
combo.Location = new Point(0, 0);
|
||||||
|
combo.Width = this.ClientRectangle.Width;
|
||||||
|
this.Height = combo.Height;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Event Handler
|
||||||
|
/// <summary>
|
||||||
|
/// We make our DropDownForm host the choosen control and show it instead
|
||||||
|
/// of the dropdown portion of the ComboBox.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void Combo_DropDown(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!_dropDownHelper.DropDownShowing)
|
||||||
|
{
|
||||||
|
DropDownForm dropDown = new DropDownForm(_dropDownControl);
|
||||||
|
|
||||||
|
|
||||||
|
dropDown.FinishEditing += new DropDownValueChangedEventHandler(DropDown_FinishEditing);
|
||||||
|
dropDown.ValueChanged += new DropDownValueChangedEventHandler(DropDown_ValueChanged);
|
||||||
|
|
||||||
|
combo.DroppedDown = false;
|
||||||
|
dropDown.Width = combo.Width; // KBR ADDED 2/15/08
|
||||||
|
_dropDownHelper.ShowDropDown(_owner, dropDown, GetDropDownPosition(dropDown));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_dropDownHelper.CloseDropDown();
|
||||||
|
this.Focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DropDownHelper_DropDownClosed(object sender, DropDownClosedEventArgs e)
|
||||||
|
{
|
||||||
|
IDropDownAware dropDown = (e.DropDown as IDropDownAware);
|
||||||
|
|
||||||
|
if ((dropDown != null) && (dropDown.Value != null))
|
||||||
|
{
|
||||||
|
dropDown.FinishEditing -= new DropDownValueChangedEventHandler(DropDown_FinishEditing);
|
||||||
|
dropDown.ValueChanged -= new DropDownValueChangedEventHandler(DropDown_ValueChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
combo.DroppedDown = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DropDownHelper_DropDownCancel(object sender, DropDownCancelEventArgs e)
|
||||||
|
{
|
||||||
|
if (this.Bounds.Contains(Parent.PointToClient(e.CursorLocation)))
|
||||||
|
{
|
||||||
|
e.Cancel = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IDropDownAware dropDown = (e.DropDown as IDropDownAware);
|
||||||
|
|
||||||
|
if (dropDown != null)
|
||||||
|
{
|
||||||
|
dropDown.FinishEditing -= new DropDownValueChangedEventHandler(DropDown_FinishEditing);
|
||||||
|
dropDown.ValueChanged -= new DropDownValueChangedEventHandler(DropDown_ValueChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DropDown_FinishEditing(object sender, DropDownValueChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Value != null)
|
||||||
|
{
|
||||||
|
SetValue<long>(e.Value as ILookupItem<long>);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.FinishEditing != null)
|
||||||
|
{
|
||||||
|
this.FinishEditing(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
_dropDownControl.FinishEditing -= new DropDownValueChangedEventHandler(DropDown_FinishEditing);
|
||||||
|
_dropDownControl.ValueChanged -= new DropDownValueChangedEventHandler(DropDown_ValueChanged);
|
||||||
|
_dropDownHelper.CloseDropDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DropDown_ValueChanged(object sender, DropDownValueChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (this.ValueChanged != null)
|
||||||
|
{
|
||||||
|
this.ValueChanged(this, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Public Properties
|
||||||
|
/// <summary>
|
||||||
|
/// Get or set the control (has to implement IDropDownAware) that is to
|
||||||
|
/// be displayed as the dropdown portion of the combobox.
|
||||||
|
/// </summary>
|
||||||
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||||
|
public IDropDownAware DropDownControl
|
||||||
|
{
|
||||||
|
get { return _dropDownControl; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_dropDownControl = value;
|
||||||
|
|
||||||
|
this.Controls.Add(_dropDownControl as Control);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Public Methods
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return this.Name;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Private Methods
|
||||||
|
/// <summary>
|
||||||
|
/// Calculate an acceptable position of the DropDownForm even in a
|
||||||
|
/// multi screen environment.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="DropDown"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private Point GetDropDownPosition(DropDownForm DropDown)
|
||||||
|
{
|
||||||
|
Point lt = Parent.PointToScreen(new Point(Left, Top));
|
||||||
|
Point rb = Parent.PointToScreen(new Point(Right, Bottom));
|
||||||
|
Rectangle screen = Screen.FromControl(this).Bounds;
|
||||||
|
Point point = new Point();
|
||||||
|
|
||||||
|
if (((lt.X + DropDown.Width) > (screen.X + screen.Width)) && ((rb.X - DropDown.Width) >= screen.X))
|
||||||
|
{
|
||||||
|
point.X = rb.X - DropDown.Width;
|
||||||
|
|
||||||
|
if ((point.X + DropDown.Width) > (screen.X + screen.Width))
|
||||||
|
{
|
||||||
|
point.X = ((screen.X + screen.Width) - DropDown.Width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
point.X = lt.X;
|
||||||
|
|
||||||
|
if (point.X < screen.X)
|
||||||
|
{
|
||||||
|
point.X = screen.X;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (((rb.Y + DropDown.Height) > (screen.Y + screen.Height)) && ((lt.Y - DropDown.Height) >= screen.Y))
|
||||||
|
{
|
||||||
|
point.Y = lt.Y - DropDown.Height;
|
||||||
|
|
||||||
|
if (point.Y < screen.Y)
|
||||||
|
{
|
||||||
|
point.Y = screen.Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
point.Y = rb.Y;
|
||||||
|
|
||||||
|
if ((point.Y + DropDown.Height) > (screen.Y + screen.Height))
|
||||||
|
{
|
||||||
|
point.Y = ((screen.Y + screen.Height) - DropDown.Height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// In this implementation we don't the user to edit the ComboBox
|
||||||
|
/// directly, so we add the new value to the item collection after
|
||||||
|
/// clearing it first.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="Value"></param>
|
||||||
|
private void SetValue<T>(ILookupItem<T> Value) where T: struct
|
||||||
|
{
|
||||||
|
if (DropDownControl != null)
|
||||||
|
{
|
||||||
|
ILookupItem<T>[] arr = new ILookupItem<T>[0];
|
||||||
|
|
||||||
|
combo.DataSource = arr;
|
||||||
|
|
||||||
|
if ((Value != null) && (Value is ILookupItem<long>))
|
||||||
|
{
|
||||||
|
DropDownControl.Value = Value;
|
||||||
|
|
||||||
|
arr = new ILookupItem<T>[1]{(ILookupItem<T>) Value};
|
||||||
|
combo.DataSource = arr;
|
||||||
|
combo.SelectedIndex = 0;
|
||||||
|
combo.Focus();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DropDownControl.Value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region IDropDownAware Implementation
|
||||||
|
/// <summary>
|
||||||
|
/// Fired either on OK, Cancel or a click outside the control to indicate
|
||||||
|
/// that the user has finished editing.
|
||||||
|
/// </summary>
|
||||||
|
public event DropDownValueChangedEventHandler FinishEditing;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fired on any change of the controls's value during the editing process.
|
||||||
|
/// </summary>
|
||||||
|
public event DropDownValueChangedEventHandler ValueChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the controls' value.
|
||||||
|
/// </summary>
|
||||||
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||||
|
public object Value
|
||||||
|
{
|
||||||
|
get { return _dropDownControl.Value; }
|
||||||
|
set { SetValue<long>(value as ILookupItem<long>); }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
77
PROMS/DropDownPanel/DropDownPanel.csproj
Normal file
77
PROMS/DropDownPanel/DropDownPanel.csproj
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>8.0.50727</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{34ADDF19-CBBA-4A11-BC99-D141BA2D29EC}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>DropDownPanel</RootNamespace>
|
||||||
|
<AssemblyName>DropDownPanel</AssemblyName>
|
||||||
|
<SccProjectName>SAK</SccProjectName>
|
||||||
|
<SccLocalPath>SAK</SccLocalPath>
|
||||||
|
<SccAuxPath>SAK</SccAuxPath>
|
||||||
|
<SccProvider>SAK</SccProvider>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<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' ">
|
||||||
|
<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.Data" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Forms\DropDownForm.cs">
|
||||||
|
<SubType>Form</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Forms\DropDownForm.designer.cs">
|
||||||
|
<DependentUpon>DropDownForm.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Controls\DropDownPanel.cs">
|
||||||
|
<SubType>UserControl</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Controls\DropDownPanel.Designer.cs">
|
||||||
|
<DependentUpon>DropDownPanel.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Helper\DropDownWindowHelper.cs" />
|
||||||
|
<Compile Include="Helper\DropDownMessageFilter.cs" />
|
||||||
|
<Compile Include="Events\Events.cs" />
|
||||||
|
<Compile Include="Interfaces\IDropDownAware.cs" />
|
||||||
|
<Compile Include="Interfaces\ILookupItem.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Unmanaged\UIApiCalls.cs" />
|
||||||
|
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Forms\DropDownForm.resx">
|
||||||
|
<DependentUpon>DropDownForm.cs</DependentUpon>
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
10
PROMS/DropDownPanel/DropDownPanel.csproj.vspscc
Normal file
10
PROMS/DropDownPanel/DropDownPanel.csproj.vspscc
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
""
|
||||||
|
{
|
||||||
|
"FILE_VERSION" = "9237"
|
||||||
|
"ENLISTMENT_CHOICE" = "NEVER"
|
||||||
|
"PROJECT_FILE_RELATIVE_PATH" = ""
|
||||||
|
"NUMBER_OF_EXCLUDED_FILES" = "0"
|
||||||
|
"ORIGINAL_PROJECT_FILE_PATH" = ""
|
||||||
|
"NUMBER_OF_NESTED_PROJECTS" = "0"
|
||||||
|
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
|
||||||
|
}
|
154
PROMS/DropDownPanel/Events/Events.cs
Normal file
154
PROMS/DropDownPanel/Events/Events.cs
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AT.STO.UI.Win
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the method which responds to a <see cref="DropDownCancel"/> event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
public delegate void DropDownCancelEventHandler(object sender, DropDownCancelEventArgs e);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the method which responds to a <see cref="DropDownClosed"/> event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
public delegate void DropDownClosedEventHandler(object sender, DropDownClosedEventArgs e);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">The object firing the event.</param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
public delegate void DropDownValueChangedEventHandler(object sender, DropDownValueChangedEventArgs e);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Arguments to a <see cref="DropDownCancelEvent"/>. Provides a
|
||||||
|
/// reference to the popup form that is to be closed and
|
||||||
|
/// allows the operation to be cancelled.
|
||||||
|
///
|
||||||
|
/// Thousand thanks to Steve McMahon:
|
||||||
|
/// http://www.vbaccelerator.com/home/NET/Code/Controls/Popup_Windows/Popup_Windows/Popup_Form_Demonstration.asp
|
||||||
|
/// </summary>
|
||||||
|
public class DropDownCancelEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
#region Private Variable Declarations
|
||||||
|
private bool _cancel = false;
|
||||||
|
private Point _cursorLocation;
|
||||||
|
private Form _dropDown = null;
|
||||||
|
#endregion
|
||||||
|
#region Constructor / Destructor
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs a new instance of this class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="DropDown">The popup form</param>
|
||||||
|
/// <param name="CursorLocation">The mouse location, if any, where the
|
||||||
|
/// mouse event that would cancel the popup occured.</param>
|
||||||
|
public DropDownCancelEventArgs(Form DropDown, Point CursorLocation)
|
||||||
|
{
|
||||||
|
_dropDown = DropDown;
|
||||||
|
_cursorLocation = CursorLocation;
|
||||||
|
_cancel = false;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Public Properties
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public bool Cancel
|
||||||
|
{
|
||||||
|
get { return _cancel; }
|
||||||
|
set { _cancel = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public Point CursorLocation
|
||||||
|
{
|
||||||
|
get { return _cursorLocation; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public Form DropDown
|
||||||
|
{
|
||||||
|
get { return _dropDown; }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains event information for a <see cref="DropDownClosed"/> event.
|
||||||
|
///
|
||||||
|
/// Thousand thanks to Steve McMahon:
|
||||||
|
/// http://www.vbaccelerator.com/home/NET/Code/Controls/Popup_Windows/Popup_Windows/Popup_Form_Demonstration.asp
|
||||||
|
/// </summary>
|
||||||
|
public class DropDownClosedEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
#region Private Variable Declarations
|
||||||
|
private Form _dropDown = null;
|
||||||
|
#endregion
|
||||||
|
#region Constructor / Destructor
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs a new instance of this class for the specified
|
||||||
|
/// popup form.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="DropDown">DropDown Form which is being closed.</param>
|
||||||
|
public DropDownClosedEventArgs(Form DropDown)
|
||||||
|
{
|
||||||
|
_dropDown = DropDown;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Public Properties
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the dropdown form which is being closed.
|
||||||
|
/// </summary>
|
||||||
|
public Form DropDown
|
||||||
|
{
|
||||||
|
get { return _dropDown; }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains event information for DropDownValueChangedEventHandler.
|
||||||
|
/// </summary>
|
||||||
|
public class DropDownValueChangedEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
#region Private Variable Declarations
|
||||||
|
private object _value = null;
|
||||||
|
#endregion
|
||||||
|
#region Constructor / Destructor
|
||||||
|
/// <summary>
|
||||||
|
/// Default Constructor
|
||||||
|
/// </summary>
|
||||||
|
public DropDownValueChangedEventArgs()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialization with the control's value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Value"></param>
|
||||||
|
public DropDownValueChangedEventArgs(object Value)
|
||||||
|
{
|
||||||
|
_value = Value;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Public Properties
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the control's value.
|
||||||
|
/// </summary>
|
||||||
|
public object Value
|
||||||
|
{
|
||||||
|
get { return _value; }
|
||||||
|
set { _value = value; }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
116
PROMS/DropDownPanel/Forms/DropDownForm.cs
Normal file
116
PROMS/DropDownPanel/Forms/DropDownForm.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AT.STO.UI.Win
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The form that pops up instead of the dropdown portion of the
|
||||||
|
/// DropDownPanel's combobox. It containes the actual control to
|
||||||
|
/// display.
|
||||||
|
/// </summary>
|
||||||
|
internal partial class DropDownForm : Form, IDropDownAware
|
||||||
|
{
|
||||||
|
#region Private Variable Declaration
|
||||||
|
private IDropDownAware _control = null;
|
||||||
|
#endregion
|
||||||
|
#region Constructor / Destructor
|
||||||
|
/// <summary>
|
||||||
|
/// Default Constructor
|
||||||
|
/// </summary>
|
||||||
|
public DropDownForm()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor to initialize the for with the control to display.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Ctrl">The control to display.</param>
|
||||||
|
public DropDownForm(IDropDownAware Ctrl) : this()
|
||||||
|
{
|
||||||
|
if (Ctrl != null)
|
||||||
|
{
|
||||||
|
_control = Ctrl;
|
||||||
|
|
||||||
|
InitializeControl(_control as Control);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Form Events
|
||||||
|
protected override void OnClosing(CancelEventArgs e)
|
||||||
|
{
|
||||||
|
this.Controls.Remove(_control as Control);
|
||||||
|
base.OnClosing(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnShown(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnShown(e);
|
||||||
|
|
||||||
|
_control.FinishEditing += new DropDownValueChangedEventHandler(Ctrl_FinishEditing);
|
||||||
|
_control.ValueChanged += new DropDownValueChangedEventHandler(Ctrl_ValueChanged);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Event Handler
|
||||||
|
private void Ctrl_FinishEditing(object sender, DropDownValueChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (this.FinishEditing != null)
|
||||||
|
{
|
||||||
|
this.FinishEditing(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
_control.FinishEditing -= new DropDownValueChangedEventHandler(Ctrl_FinishEditing);
|
||||||
|
_control.ValueChanged -= new DropDownValueChangedEventHandler(Ctrl_ValueChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Ctrl_ValueChanged(object sender, DropDownValueChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (this.ValueChanged != null)
|
||||||
|
{
|
||||||
|
this.ValueChanged(this, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region IDropDownAware Implementation
|
||||||
|
/// <summary>
|
||||||
|
/// Fired either on OK, Cancel or a click outside the control to indicate
|
||||||
|
/// that the user has finished editing.
|
||||||
|
/// </summary>
|
||||||
|
public event DropDownValueChangedEventHandler FinishEditing;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fired on any change of the controls's value during the editing process.
|
||||||
|
/// </summary>
|
||||||
|
public event DropDownValueChangedEventHandler ValueChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the controls' value.
|
||||||
|
/// </summary>
|
||||||
|
public object Value
|
||||||
|
{
|
||||||
|
get { return _control.Value; }
|
||||||
|
set { _control.Value = value; }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Private Methods
|
||||||
|
private void InitializeControl(Control Ctrl)
|
||||||
|
{
|
||||||
|
Size size = Ctrl.Size;
|
||||||
|
Size inner = this.ClientRectangle.Size;
|
||||||
|
Size outer = this.Size;
|
||||||
|
int gap = outer.Width - inner.Width;
|
||||||
|
|
||||||
|
size.Width += gap;
|
||||||
|
size.Height += gap;
|
||||||
|
|
||||||
|
this.Size = size;
|
||||||
|
this.Controls.Add(Ctrl);
|
||||||
|
Ctrl.Location = new Point(0, 0);
|
||||||
|
Ctrl.Visible = true;
|
||||||
|
Ctrl.Invalidate();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
52
PROMS/DropDownPanel/Forms/DropDownForm.designer.cs
generated
Normal file
52
PROMS/DropDownPanel/Forms/DropDownForm.designer.cs
generated
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
namespace AT.STO.UI.Win
|
||||||
|
{
|
||||||
|
partial class DropDownForm
|
||||||
|
{
|
||||||
|
/// <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.SuspendLayout();
|
||||||
|
//
|
||||||
|
// DropDownForm
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.BackColor = System.Drawing.SystemColors.Window;
|
||||||
|
this.ClientSize = new System.Drawing.Size(347, 211);
|
||||||
|
this.ControlBox = false;
|
||||||
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
||||||
|
this.MaximizeBox = false;
|
||||||
|
this.MinimizeBox = false;
|
||||||
|
this.Name = "DropDownForm";
|
||||||
|
this.ShowIcon = false;
|
||||||
|
this.ShowInTaskbar = false;
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
120
PROMS/DropDownPanel/Forms/DropDownForm.resx
Normal file
120
PROMS/DropDownPanel/Forms/DropDownForm.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
110
PROMS/DropDownPanel/Helper/DropDownMessageFilter.cs
Normal file
110
PROMS/DropDownPanel/Helper/DropDownMessageFilter.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AT.STO.UI.Win
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A Message Loop filter which detect mouse events whilst the popup form is shown
|
||||||
|
/// and notifies the owning <see cref="PopupWindowHelper"/> class when a mouse
|
||||||
|
/// click outside the popup occurs.
|
||||||
|
///
|
||||||
|
/// Thousand thanks to Steve McMahon:
|
||||||
|
/// http://www.vbaccelerator.com/home/NET/Code/Controls/Popup_Windows/Popup_Windows/Popup_Form_Demonstration.asp
|
||||||
|
/// </summary>
|
||||||
|
internal class DropDownMessageFilter : IMessageFilter
|
||||||
|
{
|
||||||
|
#region Private Constants
|
||||||
|
private const int WM_LBUTTONDOWN = 0x201;
|
||||||
|
private const int WM_RBUTTONDOWN = 0x204;
|
||||||
|
private const int WM_MBUTTONDOWN = 0x207;
|
||||||
|
private const int WM_NCLBUTTONDOWN = 0x0A1;
|
||||||
|
private const int WM_NCRBUTTONDOWN = 0x0A4;
|
||||||
|
private const int WM_NCMBUTTONDOWN = 0x0A7;
|
||||||
|
#endregion
|
||||||
|
#region Private Variable Declarations
|
||||||
|
private Form _dropDown = null;
|
||||||
|
private DropDownWindowHelper _owner = null;
|
||||||
|
#endregion
|
||||||
|
#region Event Declarations
|
||||||
|
public event DropDownCancelEventHandler DropDownCancel;
|
||||||
|
#endregion
|
||||||
|
#region Constructor / Destructor
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs a new instance of this class and sets the owning
|
||||||
|
/// object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Owner">The <see cref="DropDownWindowHelper"/> object
|
||||||
|
/// which owns this class.</param>
|
||||||
|
public DropDownMessageFilter(DropDownWindowHelper Owner)
|
||||||
|
{
|
||||||
|
_owner = Owner;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Public Properties
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/sets the dropdown form which is being displayed.
|
||||||
|
/// </summary>
|
||||||
|
public Form DropDown
|
||||||
|
{
|
||||||
|
get { return _dropDown; }
|
||||||
|
set { _dropDown = value; }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Private Methods
|
||||||
|
private void OnMouseDown()
|
||||||
|
{
|
||||||
|
Point cursorPos = Cursor.Position; // Get the cursor location
|
||||||
|
|
||||||
|
if (!_dropDown.Bounds.Contains(cursorPos)) // Check if it is within the popup form
|
||||||
|
{
|
||||||
|
OnDropDownCancel(new DropDownCancelEventArgs(_dropDown, cursorPos)); // If not, then call to see if it should be closed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region DropDownCancelEvent Implementation
|
||||||
|
protected virtual void OnDropDownCancel(DropDownCancelEventArgs e)
|
||||||
|
{
|
||||||
|
if (this.DropDownCancel != null)
|
||||||
|
{
|
||||||
|
this.DropDownCancel(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!e.Cancel)
|
||||||
|
{
|
||||||
|
_owner.CloseDropDown();
|
||||||
|
_dropDown = null; // Clear reference for GC
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region IMessageFilter Implementation
|
||||||
|
/// <summary>
|
||||||
|
/// Checks the message loop for mouse messages whilst the popup
|
||||||
|
/// window is displayed. If one is detected the position is
|
||||||
|
/// checked to see if it is outside the form, and the owner
|
||||||
|
/// is notified if so.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="m">Windows Message about to be processed by the
|
||||||
|
/// message loop</param>
|
||||||
|
/// <returns><c>true</c> to filter the message, <c>false</c> otherwise.
|
||||||
|
/// This implementation always returns <c>false</c>.</returns>
|
||||||
|
public bool PreFilterMessage(ref Message m)
|
||||||
|
{
|
||||||
|
if (_dropDown != null)
|
||||||
|
{
|
||||||
|
switch (m.Msg)
|
||||||
|
{
|
||||||
|
case WM_LBUTTONDOWN:
|
||||||
|
case WM_RBUTTONDOWN:
|
||||||
|
case WM_MBUTTONDOWN:
|
||||||
|
case WM_NCLBUTTONDOWN:
|
||||||
|
case WM_NCRBUTTONDOWN:
|
||||||
|
case WM_NCMBUTTONDOWN: OnMouseDown(); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
203
PROMS/DropDownPanel/Helper/DropDownWindowHelper.cs
Normal file
203
PROMS/DropDownPanel/Helper/DropDownWindowHelper.cs
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AT.STO.UI.Win
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A class to assist in creating popup windows like Combo Box drop-downs and Menus.
|
||||||
|
/// This class includes functionality to keep the title bar of the popup owner form
|
||||||
|
/// active whilst the popup is displayed, and to automatically cancel the popup
|
||||||
|
/// whenever the user clicks outside the popup window or shifts focus to another
|
||||||
|
/// application.
|
||||||
|
///
|
||||||
|
/// Thousand thanks to Steve McMahon:
|
||||||
|
/// http://www.vbaccelerator.com/home/NET/Code/Controls/Popup_Windows/Popup_Windows/Popup_Form_Demonstration.asp
|
||||||
|
/// </summary>
|
||||||
|
internal class DropDownWindowHelper : NativeWindow
|
||||||
|
{
|
||||||
|
#region Private Variable Declarations
|
||||||
|
private EventHandler DropDownClosedHandler = null;
|
||||||
|
|
||||||
|
private Form _dropDown = null;
|
||||||
|
private bool _dropDownShowing = false;
|
||||||
|
private DropDownMessageFilter _filter = null;
|
||||||
|
private Form _owner = null;
|
||||||
|
private bool _skipClose = false;
|
||||||
|
#endregion
|
||||||
|
#region Event Declarations
|
||||||
|
public event DropDownCancelEventHandler DropDownCancel;
|
||||||
|
public event DropDownClosedEventHandler DropDownClosed;
|
||||||
|
#endregion
|
||||||
|
#region Constructor / Destructor
|
||||||
|
/// <summary>
|
||||||
|
/// Default constructor.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Use the <see cref="System.Windows.Forms.NativeWindow.AssignHandle"/>
|
||||||
|
/// method to attach this class to the form you want to show popups from.</remarks>
|
||||||
|
public DropDownWindowHelper()
|
||||||
|
{
|
||||||
|
_filter = new DropDownMessageFilter(this);
|
||||||
|
_filter.DropDownCancel += new DropDownCancelEventHandler(Popup_Cancel);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Event Handler
|
||||||
|
private void Popup_Cancel(object sender, DropDownCancelEventArgs e)
|
||||||
|
{
|
||||||
|
OnDropDownCancel(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Responds to the <see cref="System.Windows.Forms.Form.Closed"/>
|
||||||
|
/// event from the popup form.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">Popup form that has been closed.</param>
|
||||||
|
/// <param name="e">Not used.</param>
|
||||||
|
private void Popup_Closed(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CloseDropDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Subclasses the owning form's existing Window Procedure to enables the
|
||||||
|
/// title bar to remain active when a popup is show, and to detect if
|
||||||
|
/// the user clicks onto another application whilst the popup is visible.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="m">Window Procedure Message</param>
|
||||||
|
protected override void WndProc(ref Message m)
|
||||||
|
{
|
||||||
|
base.WndProc(ref m);
|
||||||
|
|
||||||
|
if (DropDownShowing)
|
||||||
|
{
|
||||||
|
if (m.Msg == UIApiCalls.WM_NCACTIVATE)
|
||||||
|
{
|
||||||
|
if (((int)m.WParam) == 0) // Check if the title bar will made inactive:
|
||||||
|
{ // Note it's no good to try and consume this message; if you try to do that you'll end up with windows
|
||||||
|
UIApiCalls.SendMessage(this.Handle, UIApiCalls.WM_NCACTIVATE, 1, IntPtr.Zero); // If so reactivate it.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (m.Msg == UIApiCalls.WM_ACTIVATEAPP)
|
||||||
|
{
|
||||||
|
if ((int)m.WParam == 0) // Check if the application is being deactivated.
|
||||||
|
{
|
||||||
|
CloseDropDown(); // It is so cancel the popup:
|
||||||
|
UIApiCalls.PostMessage(this.Handle, UIApiCalls.WM_NCACTIVATE, 0, IntPtr.Zero); // And put the title bar into the inactive state:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Public Methods
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the specified Form as a popup window, keeping the
|
||||||
|
/// Owner's title bar active and preparing to cancel the popup
|
||||||
|
/// should the user click anywhere outside the popup window.
|
||||||
|
/// <para>Typical code to use this message is as follows:</para>
|
||||||
|
/// <code>
|
||||||
|
/// frmPopup popup = new frmPopup();
|
||||||
|
/// Point location = this.PointToScreen(new Point(button1.Left, button1.Bottom));
|
||||||
|
/// popupHelper.ShowPopup(this, popup, location);
|
||||||
|
/// </code>
|
||||||
|
/// <para>Put as much initialisation code as possible
|
||||||
|
/// into the popup form's constructor, rather than the <see cref="System.Windows.Forms.Load"/>
|
||||||
|
/// event as this will improve visual appearance.</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Owner">Main form which owns the popup</param>
|
||||||
|
/// <param name="Popup">Window to show as a popup</param>
|
||||||
|
/// <param name="v">Location relative to the screen to show the popup at.</param>
|
||||||
|
public void ShowDropDown(Form Owner, Form DropDown, Point Location)
|
||||||
|
{
|
||||||
|
_owner = Owner;
|
||||||
|
_dropDown = DropDown;
|
||||||
|
Application.AddMessageFilter(_filter); // Start checking for the popup being cancelled
|
||||||
|
DropDown.StartPosition = FormStartPosition.Manual; // Set the location of the popup form:
|
||||||
|
DropDown.Location = Location;
|
||||||
|
Owner.AddOwnedForm(DropDown); // Make it owned by the window that's displaying it:
|
||||||
|
DropDownClosedHandler = new EventHandler(Popup_Closed); // Respond to the Closed event in case the popup is closed by its own internal means
|
||||||
|
DropDown.Closed += DropDownClosedHandler;
|
||||||
|
|
||||||
|
_dropDownShowing = true; // Show the popup:
|
||||||
|
DropDown.Show();
|
||||||
|
DropDown.Activate();
|
||||||
|
|
||||||
|
// A little bit of fun. We've shown the popup, but because we've kept the main window's
|
||||||
|
// title bar in focus the tab sequence isn't quite right. This can be fixed by sending a tab,
|
||||||
|
// but that on its own would shift focus to the second control in the form. So send a tab,
|
||||||
|
// followed by a reverse-tab.
|
||||||
|
UIApiCalls.keybd_event((byte) Keys.Tab, 0, 0, 0);
|
||||||
|
UIApiCalls.keybd_event((byte) Keys.Tab, 0, UIApiCalls.KEYEVENTF_KEYUP, 0);
|
||||||
|
UIApiCalls.keybd_event((byte) Keys.ShiftKey, 0, 0, 0);
|
||||||
|
UIApiCalls.keybd_event((byte) Keys.Tab, 0, 0, 0);
|
||||||
|
UIApiCalls.keybd_event((byte) Keys.Tab, 0, UIApiCalls.KEYEVENTF_KEYUP, 0);
|
||||||
|
UIApiCalls.keybd_event((byte) Keys.ShiftKey, 0, UIApiCalls.KEYEVENTF_KEYUP, 0);
|
||||||
|
|
||||||
|
_filter.DropDown = DropDown; // Start filtering for mouse clicks outside the popup
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the popup is being hidden.
|
||||||
|
/// </summary>
|
||||||
|
public void CloseDropDown()
|
||||||
|
{
|
||||||
|
if (DropDownShowing)
|
||||||
|
{
|
||||||
|
if (!_skipClose)
|
||||||
|
{
|
||||||
|
OnPDropDownClosed(new DropDownClosedEventArgs(_dropDown));
|
||||||
|
}
|
||||||
|
|
||||||
|
_skipClose = false;
|
||||||
|
|
||||||
|
_owner.RemoveOwnedForm(_dropDown); // Make sure the popup is closed and we've cleaned up:
|
||||||
|
_dropDownShowing = false;
|
||||||
|
_dropDown.Closed -= DropDownClosedHandler;
|
||||||
|
DropDownClosedHandler = null;
|
||||||
|
_dropDown.Close();
|
||||||
|
|
||||||
|
Application.RemoveMessageFilter(_filter); // No longer need to filter for clicks outside the popup.
|
||||||
|
|
||||||
|
// If we did something from the popup which shifted focus to a new form, like showing another popup
|
||||||
|
// or dialog, then Windows won't know how to bring the original owner back to the foreground, so
|
||||||
|
// force it here:
|
||||||
|
_owner.Activate();
|
||||||
|
|
||||||
|
_dropDown = null; // Null out references for GC
|
||||||
|
_owner = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Public Properties
|
||||||
|
/// <summary>
|
||||||
|
/// Indicator weither the DropDown is showing.
|
||||||
|
/// </summary>
|
||||||
|
public bool DropDownShowing
|
||||||
|
{
|
||||||
|
get { return _dropDownShowing; }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
#region Event Implementation
|
||||||
|
protected virtual void OnDropDownCancel(DropDownCancelEventArgs e)
|
||||||
|
{
|
||||||
|
if (this.DropDownCancel != null)
|
||||||
|
{
|
||||||
|
this.DropDownCancel(this, e);
|
||||||
|
|
||||||
|
if (!e.Cancel)
|
||||||
|
{
|
||||||
|
_skipClose = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnPDropDownClosed(DropDownClosedEventArgs e)
|
||||||
|
{
|
||||||
|
if (this.DropDownClosed != null)
|
||||||
|
{
|
||||||
|
this.DropDownClosed(this, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
30
PROMS/DropDownPanel/Interfaces/IDropDownAware.cs
Normal file
30
PROMS/DropDownPanel/Interfaces/IDropDownAware.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace AT.STO.UI.Win
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Standard interface that has to be implemented by control's that
|
||||||
|
/// should be diplayed in the dropdown area of the DropDownPanel.
|
||||||
|
/// </summary>
|
||||||
|
public interface IDropDownAware
|
||||||
|
{
|
||||||
|
#region Event Declarations
|
||||||
|
/// <summary>
|
||||||
|
/// Fired either on OK, Cancel or a click outside the control to indicate
|
||||||
|
/// that the user has finished editing.
|
||||||
|
/// </summary>
|
||||||
|
event DropDownValueChangedEventHandler FinishEditing;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fired on any change of the controls's value during the editing process.
|
||||||
|
/// </summary>
|
||||||
|
event DropDownValueChangedEventHandler ValueChanged;
|
||||||
|
#endregion
|
||||||
|
#region Public Properties
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the controls' value.
|
||||||
|
/// </summary>
|
||||||
|
object Value { get; set; }
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
10
PROMS/DropDownPanel/Interfaces/ILookupItem.cs
Normal file
10
PROMS/DropDownPanel/Interfaces/ILookupItem.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace AT.STO.UI.Win
|
||||||
|
{
|
||||||
|
public interface ILookupItem<T> where T: struct
|
||||||
|
{
|
||||||
|
T Id { get; }
|
||||||
|
string Text { get; }
|
||||||
|
}
|
||||||
|
}
|
35
PROMS/DropDownPanel/Properties/AssemblyInfo.cs
Normal file
35
PROMS/DropDownPanel/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("DropDownPanel")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("DropDownPanel")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2007")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("d59d03fc-b0ff-4210-867d-cfa4cef1728c")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Revision and Build Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
[assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
25
PROMS/DropDownPanel/Unmanaged/UIApiCalls.cs
Normal file
25
PROMS/DropDownPanel/Unmanaged/UIApiCalls.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace AT.STO.UI.Win
|
||||||
|
{
|
||||||
|
public static class UIApiCalls
|
||||||
|
{
|
||||||
|
#region Public Constants
|
||||||
|
public const int WM_ACTIVATE = 0x006;
|
||||||
|
public const int WM_ACTIVATEAPP = 0x01C;
|
||||||
|
public const int WM_NCACTIVATE = 0x086;
|
||||||
|
public const int KEYEVENTF_KEYUP = 0x0002;
|
||||||
|
#endregion
|
||||||
|
#region Public Static API Calls
|
||||||
|
[DllImport("user32", CharSet = CharSet.Auto)]
|
||||||
|
public extern static int SendMessage(IntPtr handle, int msg, int wParam, IntPtr lParam);
|
||||||
|
|
||||||
|
[DllImport("user32", CharSet = CharSet.Auto)]
|
||||||
|
public extern static int PostMessage(IntPtr handle, int msg, int wParam, IntPtr lParam);
|
||||||
|
|
||||||
|
[DllImport("user32")]
|
||||||
|
public extern static void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user