C
C#12mo ago
Soggy

User Control Eventhandler. How to get my control's components to inherit an Eventhandler.

I have a User Control called BoxButton that I want to behave like a Button, I want my PictureBox and TextBox to call or invoke BoxButton.Click.
No description
3 Replies
Soggy
SoggyOP12mo ago
some things I've tried include: Doesn't work with windows designer code due to syntax, I have to manually type BoxButton.Click = BoxButton_Click rather than BoxButton.Click += BoxButton_Click.
public new EventHandler? Click
{
set
{
Picture.Click += value;
TextBox.Click += value;
base.Click += value;
}
}
public new EventHandler? Click
{
set
{
Picture.Click += value;
TextBox.Click += value;
base.Click += value;
}
}
Doesn't work :<
private void picture_click(object sender, EventArgs e) => this.Click += picture_click;
private void text_click(object sender, EventArgs e) => this.Click += text_click;
private void picture_click(object sender, EventArgs e) => this.Click += picture_click;
private void text_click(object sender, EventArgs e) => this.Click += text_click;
something like this also doesn't work
public BoxButton() : base()
{
InitializeComponent();
Picture.Click += this.Click;
TextBox.Click += this.Click;
}
public BoxButton() : base()
{
InitializeComponent();
Picture.Click += this.Click;
TextBox.Click += this.Click;
}
Error CS0079 "The event 'Control.Click' can only appear on the left hand side of += or -="
br4kejet
br4kejet12mo ago
So you want a button with an icon and, i assume, some text that the user can't type into?
Soggy
SoggyOP12mo ago
no it's readonly and only for display, label doesn't dock properly so I use a textbox but yeah pretty much, that's what I want.
Want results from more Discord servers?
Add your server