yanmai
Goto Top

C-sharp Das aktive von 2 Scintillas ausgeben

Hallo ihr Administratoren,
ich habe auf 2 panels jeweils ein Scintilla. Um z.B. Text in das aktive Scintilla einzufügen, habe ich mir eine Methode gebastelt:

private Scintilla GetCurrentScintilla()
        {
            try
            {
                if (c1active())
                    return this.panel9.Controls as Scintilla;
                else if (c2active())
                    return this.panel13.Controls as Scintilla;
                else
                    return null;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }

        private bool c1active()
        {
            try
            {
                Scintilla c = this.panel9.Controls as Scintilla;
                if (c != null)
                {
                    if (c.Focused)
                        return true;
                    else
                        return false;
                }
                else
                    return false;
            }
            catch(Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
        }
        private bool c2active()
        {
            try
            {
                Scintilla c = this.panel13.Controls as Scintilla;
                if (c != null)
                {
                    if (c.Focused)
                        return true;
                    else
                        return false;
                }
                else
                    return false;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
        }

Aber jetzt gibt es das Problem, manchmal funktioniert es, manchmal nicht. Wie kann man das lösen? Gibt es eine andere, bessere Methode?

Content-Key: 334553

Url: https://administrator.de/contentid/334553

Ausgedruckt am: 28.03.2024 um 22:03 Uhr

Mitglied: 132895
132895 08.04.2017 aktualisiert um 19:12:08 Uhr
Goto Top
Was für Gorillas?
Vielleicht gehst du mal in den städtischen Zoo, dann weißt du sicher welcher gerade die Banane schwingt face-smile.
Mitglied: Yanmai
Yanmai 08.04.2017 um 22:30:49 Uhr
Goto Top
Naja, dass sind Plugins für die Textbearbeitung
Mitglied: 132895
132895 09.04.2017 aktualisiert um 19:56:05 Uhr
Goto Top
Dann nehm doch einfach das Enter-Event und setze eine public var mit dem aktiven Scintilla face-wink

namespace WindowsFormsApplication1 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        public ScintillaNET.Scintilla ActiveScintilla = null;

        private void sc1_Enter(object sender, EventArgs e) {
            ActiveScintilla = sc1;
        }
        private void sc2_Enter(object sender, EventArgs e) {
            ActiveScintilla = sc2;
        }
    }
}