Incorporation of different method's arguments in a new method
Incorporation of different method's arguments in a new method
27 Jun 2024, 09:30
Hi guys,
I've created a Togglebutton, and i'd like to code some behaviour whereby the output of the button changes depending on what keyboard key i have held down when the button is pressed.
I've created the button, and the call to the method:
Highlight = new ToggleButton
{
Text = "HIGHLIGHT",
BackgroundColor = Color.Gray,
ForegroundColor = Color.White,
Height = 50,
Width = 100
};
Highlight.Click += Highlight_Click;
private void Highlight_Click(ToggleButtonEventArgs obj)
{
}
I understand i'd need the args from Chart.KeyDown, but if i add them like this:
private void Highlight_Click(ToggleButtonEventArgs obj, ref ChartKeyboardEventArgs args)
{
}
I receive an error: “No overload for ”Highlight Click" matches delegate ‘Action<ToggleButtonEventArgs>’
I'm not new to coding, but i am self taught, so i do have large gaps in my knowledge, and this is currently outside my understanding.
Could anyone assist/explain what i'd need to do?
Thanks in advance
Replies
Giorgi_1
28 Jun 2024, 02:21
RE: Incorporation of different method's arguments in a new method
PanagiotisCharalampous said:
Hi there,
You can't just pass parameters to a method arbitrarily. If you want to record which mouse key was pressed, use Chart.KeyDown event
Best regards,
Panagiotis
Thanks Panagiotis, i did think the above wouldn't work, it was just more of an attempt to understand how i would achieve it. Could you show/explain how it could be achieved?
Thanks in advance
@Giorgi_1
PanagiotisCharalampous
28 Jun 2024, 07:15
RE: RE: Incorporation of different method's arguments in a new method
Giorgi_1 said:
PanagiotisCharalampous said:
Hi there,
You can't just pass parameters to a method arbitrarily. If you want to record which mouse key was pressed, use Chart.KeyDown event
Best regards,
Panagiotis
Thanks Panagiotis, i did think the above wouldn't work, it was just more of an attempt to understand how i would achieve it. Could you show/explain how it could be achieved?
Thanks in advance
Hi there,
As per my previous post, if you want to capture which button was pressed you need to use the Chart.KeyDows event. Here is a small example
protected override void Initialize()
{
Chart.KeyDown += Chart_KeyDown;
}
private void Chart_KeyDown(ChartKeyboardEventArgs obj)
{
Print(obj.Key);
}
Best regards,
Panagiotis
@PanagiotisCharalampous
Giorgi_1
28 Jun 2024, 07:26
RE: RE: RE: Incorporation of different method's arguments in a new method
PanagiotisCharalampous said:
Giorgi_1 said:
PanagiotisCharalampous said:
Hi there,
You can't just pass parameters to a method arbitrarily. If you want to record which mouse key was pressed, use Chart.KeyDown event
Best regards,
Panagiotis
Thanks Panagiotis, i did think the above wouldn't work, it was just more of an attempt to understand how i would achieve it. Could you show/explain how it could be achieved?
Thanks in advance
Hi there,
As per my previous post, if you want to capture which button was pressed you need to use the Chart.KeyDows event. Here is a small example
protected override void Initialize() { Chart.KeyDown += Chart_KeyDown; } private void Chart_KeyDown(ChartKeyboardEventArgs obj) { Print(obj.Key); }
Best regards,
Panagiotis
Thanks Panagiotis. Perhaps i can clarify further using code:
Do you know if it's possible to do something like:
private void Highlight_Click(ToggleButtonEventArgs obj, ChartKeyboardEventArgs keyobj)
{
if(keyobj.AltKey)
{
if(obj.ToggleButton.BackgroundColor == Color.Green)
{
Print("Option1");
}
}
if(!keyobj.AltKey)
{
if(obj.ToggleButton.BackgroundColor == Color.Green)
{
Print("Option2");
}
I'm trying to use a single method but incorporate the keydown events, as well as the togglebutton events. Is that something that can be done?
@Giorgi_1
PanagiotisCharalampous
28 Jun 2024, 08:14
RE: RE: RE: RE: Incorporation of different method's arguments in a new method
Giorgi_1 said:
PanagiotisCharalampous said:
Giorgi_1 said:
PanagiotisCharalampous said:
Hi there,
You can't just pass parameters to a method arbitrarily. If you want to record which mouse key was pressed, use Chart.KeyDown event
Best regards,
Panagiotis
Thanks Panagiotis, i did think the above wouldn't work, it was just more of an attempt to understand how i would achieve it. Could you show/explain how it could be achieved?
Thanks in advance
Hi there,
As per my previous post, if you want to capture which button was pressed you need to use the Chart.KeyDows event. Here is a small example
protected override void Initialize() { Chart.KeyDown += Chart_KeyDown; } private void Chart_KeyDown(ChartKeyboardEventArgs obj) { Print(obj.Key); }
Best regards,
Panagiotis
Thanks Panagiotis. Perhaps i can clarify further using code:
Do you know if it's possible to do something like:
private void Highlight_Click(ToggleButtonEventArgs obj, ChartKeyboardEventArgs keyobj)
{
if(keyobj.AltKey)
{
if(obj.ToggleButton.BackgroundColor == Color.Green)
{
Print("Option1");
}
}
if(!keyobj.AltKey)
{
if(obj.ToggleButton.BackgroundColor == Color.Green)
{
Print("Option2");
}
I'm trying to use a single method but incorporate the keydown events, as well as the togglebutton events. Is that something that can be done?
No this is not possible
@PanagiotisCharalampous
Giorgi_1
28 Jun 2024, 08:16
RE: RE: RE: RE: RE: Incorporation of different method's arguments in a new method
PanagiotisCharalampous said:
Giorgi_1 said:
PanagiotisCharalampous said:
Giorgi_1 said:
PanagiotisCharalampous said:
Hi there,
You can't just pass parameters to a method arbitrarily. If you want to record which mouse key was pressed, use Chart.KeyDown event
Best regards,
Panagiotis
Thanks Panagiotis, i did think the above wouldn't work, it was just more of an attempt to understand how i would achieve it. Could you show/explain how it could be achieved?
Thanks in advance
Hi there,
As per my previous post, if you want to capture which button was pressed you need to use the Chart.KeyDows event. Here is a small example
protected override void Initialize() { Chart.KeyDown += Chart_KeyDown; } private void Chart_KeyDown(ChartKeyboardEventArgs obj) { Print(obj.Key); }
Best regards,
Panagiotis
Thanks Panagiotis. Perhaps i can clarify further using code:
Do you know if it's possible to do something like:
private void Highlight_Click(ToggleButtonEventArgs obj, ChartKeyboardEventArgs keyobj)
{
if(keyobj.AltKey)
{
if(obj.ToggleButton.BackgroundColor == Color.Green)
{
Print("Option1");
}
}
if(!keyobj.AltKey)
{
if(obj.ToggleButton.BackgroundColor == Color.Green)
{
Print("Option2");
}
I'm trying to use a single method but incorporate the keydown events, as well as the togglebutton events. Is that something that can be done?
No this is not possible
No problem at all :) I wasn't sure if it was possible but i just didn't know how to do it, or if it wasn't possible at all.
Thanks for your help and time Panagiotis
@Giorgi_1
Giorgi_1
28 Jun 2024, 08:16
RE: RE: RE: RE: RE: Incorporation of different method's arguments in a new method
PanagiotisCharalampous said:
Giorgi_1 said:
PanagiotisCharalampous said:
Giorgi_1 said:
PanagiotisCharalampous said:
Hi there,
You can't just pass parameters to a method arbitrarily. If you want to record which mouse key was pressed, use Chart.KeyDown event
Best regards,
Panagiotis
Thanks Panagiotis, i did think the above wouldn't work, it was just more of an attempt to understand how i would achieve it. Could you show/explain how it could be achieved?
Thanks in advance
Hi there,
As per my previous post, if you want to capture which button was pressed you need to use the Chart.KeyDows event. Here is a small example
protected override void Initialize() { Chart.KeyDown += Chart_KeyDown; } private void Chart_KeyDown(ChartKeyboardEventArgs obj) { Print(obj.Key); }
Best regards,
Panagiotis
Thanks Panagiotis. Perhaps i can clarify further using code:
Do you know if it's possible to do something like:
private void Highlight_Click(ToggleButtonEventArgs obj, ChartKeyboardEventArgs keyobj)
{
if(keyobj.AltKey)
{
if(obj.ToggleButton.BackgroundColor == Color.Green)
{
Print("Option1");
}
}
if(!keyobj.AltKey)
{
if(obj.ToggleButton.BackgroundColor == Color.Green)
{
Print("Option2");
}
I'm trying to use a single method but incorporate the keydown events, as well as the togglebutton events. Is that something that can be done?
No this is not possible
No problem at all :) I wasn't sure if it was possible but i just didn't know how to do it, or if it wasn't possible at all.
Thanks for your help and time Panagiotis
@Giorgi_1
PanagiotisCharalampous
27 Jun 2024, 13:03
Hi there,
You can't just pass parameters to a method arbitrarily. If you want to record which mouse key was pressed, use Chart.KeyDown event
Best regards,
Panagiotis
@PanagiotisCharalampous