Tim Bureck
Erfahrenes Mitglied
Ich habe mich jetzt den ganzen Tag damit aufgehalten, ein eigenes UserControl zu schreiben, das auch über die VS ToolBox bedienbar ist. Leider ohne wirklichen Erfolg. Ich kann das Control nirgends sehen oder aktivieren... Sämtliche Tutorials/Codeschnipsel haben mich kein Stück weiter gebracht, keine Ahnung was ich falsch mache.
Im Folgenden mal das, was ich gemacht habe:
NFZDrawPanel.cs
NFZDrawPanelToolboxItem.cs
Weiterhin gibt es noch eine NFZDrawPanel.bmp, die als Bildchen angezeigt werden soll. Der Codeaufbau orientiert sich an dieses Tutorial, aber irgendwie will es nicht so...
Bin für jede Hilfe dankbar,
Best regards
Im Folgenden mal das, was ich gemacht habe:
NFZDrawPanel.cs
C#:
[ToolboxItem(typeof(NFZDrawPanelToolboxItem))]
[ToolboxBitmap("DrawPanel.bmp")]
public partial class NFZDrawPanel : UserControl {
public static readonly int ZOOM_STANDARD = 1;
public static readonly int ZOOM_MINIMUM = 1;
public static readonly int ZOOM_MAXIMUM = 16;
private NFZCarView carView;
private int zoomLevel;
public NFZDrawPanel() {
this.carView = null;
this.ZoomLevel = NFZDrawPanel.ZOOM_STANDARD;
InitializeComponent();
}
#region Event handling
protected override void OnPaint(PaintEventArgs pe) {
base.OnPaint(pe);
}
protected override void OnMouseClick(MouseEventArgs e) {
base.OnMouseClick(e);
}
protected override void OnMouseWheel(MouseEventArgs e) {
base.OnMouseWheel(e);
}
#endregion
#region Properties
public int ZoomLevel {
get { return this.zoomLevel; }
set {
if (value < NFZDrawPanel.ZOOM_MINIMUM || value > NFZDrawPanel.ZOOM_MAXIMUM) {
throw new ArgumentException("The zoom level must be between " +
NFZDrawPanel.ZOOM_MINIMUM + " and " + NFZDrawPanel.ZOOM_MAXIMUM + ".");
}
this.zoomLevel = value;
}
}
public NFZCarView CarView {
get { return this.carView; }
set {
if (value == null) {
throw new ArgumentNullException("The car view may not be null.");
}
this.carView = value;
}
}
#endregion
}
NFZDrawPanelToolboxItem.cs
C#:
[Serializable]
public class NFZDrawPanelToolboxItem : ToolboxItem {
public NFZDrawPanelToolboxItem() : base(typeof(NFZDrawPanel)) { }
public NFZDrawPanelToolboxItem(SerializationInfo info, StreamingContext context) {
this.Deserialize(info, context);
}
protected override IComponent[] CreateComponentsCore(IDesignerHost host) {
NFZDrawPanel drawPanel = ((NFZDrawPanel) host.CreateComponent(typeof(NFZDrawPanel)));
return new IComponent[] { drawPanel };
}
}
Weiterhin gibt es noch eine NFZDrawPanel.bmp, die als Bildchen angezeigt werden soll. Der Codeaufbau orientiert sich an dieses Tutorial, aber irgendwie will es nicht so...
Bin für jede Hilfe dankbar,
Best regards