DotNetUserControl
Informationen
- Kategorien: GUI | Steuerelemente
- Version: 15.0.0.3401
- Veröffentlichungsdatum: Mittwoch, 8. Februar 2012
- Entwickler: Schulze
- Benötigt Datenbankänderung: Nein
- Betreff: DotNetUserControl
Beschreibung
Im Frontend wurde ein neuer Steuerelement--Typ "DotNetUserControl" eingebaut.
Die Nutzung geschieht folgendermaßen:
zum Einbinden wird ein .NET-UserControl benötigt (Implementierung der Schnittstelle System.Windows.Forms.IUserControl) welches zusätzliche die generische pit-Schnittstelle "IUserControl" für ein NurLese-Steuerelement bzw. "IEditableUserControl" für ein Lese-/Schreib-Steuerelement implementiert, die pit-Schnittstellen befinden sich im Namespace PitFM.Frontend.Controls in CliControl.dll
in SysControl (pit - IS Metadaten) sind im "DotNetUserControl"-Steuerelement die Datenfelder ASSEMBLY => Name der DLL mit der UserControl-Klasse und USERCONTROLCLASS => vollständiger Name der UserControl-Klasse (mit Namespace) zu füllen
Zur Laufzeit muss die Assembly im bin-Ordner vorhanden sein.
Erläuterungen der Schnittstelle sind in der DLL implementiert und werden in Visual Studio angezeigt (Object Browser, Intellisense).
Bilder
Beispielcode
//
// C# - Projekt
//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyUserCtrl
{
// UserControl1.Designer.cs
//
partial class UserControl1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
private void InitializeComponent()
{
this.textBox1 = new MyUserCtrl.MyTextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBox1.Location = new System.Drawing.Point(0, 0);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(85, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
this.textBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.textBox1_MouseUp);
//
//
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.textBox1);
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(85, 22);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private textBox1;
}
// UserControl1.cs
//
public partial class UserControl1 : UserControl, PitFM.Frontend.Controls.IEditableUserControl< string >
{
int m_nCurrentEntityHandle;
public event PitFM.Frontend.Controls.Events.AttributeValueChangedEventHandler<string> AttributeValueChanged;
public event PitFM.Frontend.Controls.Events.CurrentEntityHandleChangedEventHandler CurrentEntityHandleChanged;
public event PitFM.Frontend.Controls.Events.ContextMenuShowingEventHandler ContextMenuShowing;
public UserControl1()
{
InitializeComponent();
}
public string AttributeValue
{
get
{
return textBox1.Text;
}
set
{
textBox1.Text = value;
}
}
public int CurrentEntityHandle
{
get
{
return m_nCurrentEntityHandle;
}
set
{
m_nCurrentEntityHandle = value;
}
}
public bool IsEnabled
{
get
{
return textBox1.Enabled;
}
set
{
textBox1.Enabled = value;
}
}
public bool IsReadOnly
{
get
{
return textBox1.ReadOnly;
}
set
{
textBox1.ReadOnly = value;
}
}
public string NullValue
{
get
{
return null;
}
}
public Dictionary<string, string > DataArray
{
set
{
}
}
private void StoreValue()
{
if ( AttributeValueChanged != null )
{
AttributeValueChanged(this, new PitFM.Frontend.Controls.Events.AttributeValueChangedEventArgs<string>(textBox1.Text));
}
}
private void textBox1_Leave(object sender, EventArgs e)
{
StoreValue();
}
private void textBox1_MouseUp(object sender, MouseEventArgs e)
{
if ( e.Button==MouseButtons.Right && ContextMenuShowing != null )
{
ContextMenuShowing( this, new PitFM.Frontend.Controls.Events.ContextMenuShowingEventArgs(new Point(e.X, e.Y)));
}
}
}
public class MyTextBox : TextBox
{
public MyTextBox()
{
// Verhindern dass das Kontextmenu angezeigt wird
//
ContextMenu = new ContextMenu();
}
protected override void WndProc(ref Message m)
{
base.WndProc( ref m );
if ( m.Msg == 8 ) // KillFocus
{
OnLeave( new EventArgs() );
}
}
}
}