Autor Beitrag
chris300695
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: So 11.12.11 17:04 
Hey Leute,

brauche mal wieder eure Hilfe.

Ich will bei Klick auf ein Label, dass der Text markiert wird und ich ihn überschreiben kann. Habe dazu im Web leider nichts gefunden,
ich hoffe dass ihr mir da heflfen könnt.


Gruß

Chris
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4795
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: So 11.12.11 19:59 
Hallo Chris,

meinst du wirklich ein Label oder aber eine TextBox?
chris300695 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: So 11.12.11 20:26 
ja, ich meine schon ein Label, bei einer Textbox wäre es ja kein Problem.

Geht das mit einem Label überhaupt?
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4795
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: So 11.12.11 20:35 
Nein, von sich aus nicht. Du müßtest dann eine TextBox (temporär) darüberlegen und anschließend (z.B. bei Return/Enter) wieder löschen (bzw. verstecken) und den Text für das Label übernehmen.
C#
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 561
Erhaltene Danke: 65

Windows 10, Kubuntu, Android
Visual Studio 2017, C#, C++/CLI, C++/CX, C++, F#, R, Python
BeitragVerfasst: So 11.12.11 22:46 
ja das wäre die beste Lösung dafür.
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
private void Label1_Click(object sender, EventArgs e)
{
 TextBox textBox = new TextBox{Text = Label1.Text, Location = Label1.Location};
 Label1.Visible = false;
 textBox.SelectAll();
 textBox.Visible = true;
 textBox.KeyDown += TextBox1_KeyDown;
}

private void TexBox1_KeyDown(object sender, KeyEventArgs e)
{
 //Hier die ganze Prozedur umkehren...
}

sowas in der Art

_________________
Der längste Typ-Name im .NET-Framework ist: ListViewVirtualItemsSelectionRangeChangedEventHandler
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: So 11.12.11 23:49 
Du könntest auch statt den Labels TextBox-Controls nehmen, die du dann wie Labels aussehen lässt:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
    private void textBox1_Enter(object sender, EventArgs e) {
      textBox1.BorderStyle = BorderStyle.Fixed3D;
      textBox1.BackColor = SystemColors.Window;
      textBox1.SelectAll();
      textBox1.Cursor = Cursors.IBeam;
    }

    private void textBox1_Leave(object sender, EventArgs e) {
      textBox1.BorderStyle = BorderStyle.None;
      textBox1.BackColor = SystemColors.Control;
      textBox1.Select(00);
      textBox1.Cursor = Cursors.Arrow;
    }

    private void textBox1_KeyDown(object sender, KeyEventArgs e) {
      if (e.KeyCode == Keys.Enter) {
        textBox1_Leave(nullnull);
        button1.Focus();
      }
    }

Bei Programmstart muss textBox1_Leave aufgerufen werden, um das Control wie ein Label aussehen zu lassen.
mo0n_
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 50

Win7
C#
BeitragVerfasst: Mi 25.01.12 17:30 
nichtmal danke sagt er :-/