Autor Beitrag
mr tobo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: So 14.12.08 14:44 
Hallo Leute.
Für ein Programm, welches den geregelten Ablauf während meiner Abwesenheit regeln soll, brauche ich eine MouseClick simulation.
Im Manual steht darüber folgendes:
Zitat:

The best way to simulate mouse events is to call the OnEventName method that raises the mouse event you want to simulate. This option is usually possible only within custom controls and forms, because the methods that raise events are protected and cannot be accessed outside the control or form. For example, the following steps illustrate how to simulate clicking the right mouse button in code.

To programmatically click the right mouse button
Create a MouseEventArgs whose Button property is set to the MouseButtons.Right value.

Call the OnMouseClick method with this MouseEventArgs as the argument.


In meinem beispiel-Programm hab ich es so gecodet:
ausblenden C#-Quelltext
1:
2:
            MouseEventArgs mymouseeventarg = new MouseEventArgs(MouseButtons.Right, 1100,1200);
            OnMouseClick(mymouseeventarg);


Parameter 1 : welcher mousebutton gedrückt wurde
Parameter 2 : Anzahl Clicks
Parameter 3 : X-Koordinaten
Parameter 4 : Y-koordinaten
Parameter 5 : delta?? "A signed Count of the number of detents the whell has rotated

1. was bewirkt der Parameter delta?
2. wie muss ich das umschreiben, damit es funktioniert?

mfg
mr tobo


Moderiert von user profile iconChristian S.: Topic aus C# - Die Sprache verschoben am So 14.12.2008 um 13:47
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 14.12.08 14:53 
user profile iconmr tobo hat folgendes geschrieben Zum zitierten Posting springen:
1. was bewirkt der Parameter delta?
Er gibt an um wie viel das Mausrad gedreht wurde, dieser Parameter sollte hier keine Rolle spielen.

user profile iconmr tobo hat folgendes geschrieben Zum zitierten Posting springen:
2. wie muss ich das umschreiben, damit es funktioniert?
Es sieht wie im Beispiel aus, vielleicht steht das an der falschen Stelle?
mr tobo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: So 14.12.08 14:57 
Danke für deine antwort.
Dass es an der falschen Stelle steht ist fast nicht möglich da ich ein ganz kurzes Beispiel-rogramm mit 2 buttons erstellt habe...
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: So 14.12.08 15:02 
Du löst das MouseClick-Event der Form aus. Wenn du aber den Eventhandler an einen Button gehängt hast, wird dir das nicht viel bringen. Und da OnMouseClick eben protected ist, kannst du es auch nicht direkt beim Button auslösen.
user profile iconmr tobo hat folgendes geschrieben Zum zitierten Posting springen:
Für ein Programm, welches den geregelten Ablauf während meiner Abwesenheit regeln soll, brauche ich eine MouseClick simulation.
:?: Wenn du das Programm sowieso selbst geschrieben hast, wieso schreibst du es dann nicht so um, dass der Button gar nicht geklickt werden muss? GUI-Simulationen benötgit man normalerweise höchstens beim Testen.

_________________
>λ=
mr tobo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: So 14.12.08 15:10 
das mit den buttons ist nur ein Testprogramm, um das mit der MouseClick-Simulation zu testen, das wirkliche Programm sieht anders aus.
Und ich versteh nicht ganz wie du meinst?
In meinem Textprogram soll einfach wenn der 1te button geklickt worde ist, der zweite button eklickt werden.
wie kann ich das jetzt also codemässig umsetzen?
mr tobo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: So 14.12.08 17:44 
ok kha jetzt verstehe ich deinen post. aber trotzdem, bei mir sollte es gehen, so wie ich es mache:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void Mouse_click(int x, int y)
        {
            MouseEventArgs mymouseeventarg = new MouseEventArgs(MouseButtons.Left, 1, x, y, 0);
            this.OnMouseClick(mymouseeventarg);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Mouse_click(200,70);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form1.ActiveForm.BackColor = Color.Red;
        }
    }
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: So 14.12.08 18:58 
user profile iconmr tobo hat folgendes geschrieben Zum zitierten Posting springen:
das mit den buttons ist nur ein Testprogramm, um das mit der MouseClick-Simulation zu testen, das wirkliche Programm sieht anders aus.
Und ich versteh nicht ganz wie du meinst?
Nun ja... wenn du in deinem Programm einen Button auslösen willst, um eine Methode zu starten, könntest du doch gleich die Methode selbst aufrufen :gruebel: ?

Und dein Code bestätigt meine Vermutung: "button2_Click" ist doch sicherlich an das Event von button2 angehängt, du rufst aber das der Form auf.

_________________
>λ=