Autor Beitrag
Ritzeratze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 101



BeitragVerfasst: Sa 18.10.14 16:25 
Moin,

aus einen Formular rufe ich eine Unterform auf. Hieraus möchte ich zwei Werte an eine Picturebox übergeben (Breite und Höhe). Allerdings habe ich beim Debuggen festgestellt, das die Werte nicht übernommen werden. Kann mir jemand einen Tipp geben ?

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:
24:
// Aufruf des Formulars aus dem Hauptprogramm
void Bildgroesse()
{      
      // hier wird das Formular frm_NeuesBild aufgerufen, in dem der Anwender die Möglichkeit hat, die Größe der PictureBox zu bestimmen 
      frm_NeuesBild FrageBildgroesse = new frm_NeuesBild();
      FrageBildgroesse.ShowDialog();

      if (FrageBildgroesse.DialogResult == DialogResult.OK)
      {
        pictureBox1.Width = FrageBildgroesse.LiefereWeite();
        pictureBox1.Height = FrageBildgroesse.LiefereHoehe();
      }
}

// aus dem Formular "frm_NeuesBild wird die 
public int LiefereWeite()
{
    return Convert.ToInt32(textBoxBreite.Text);
}

public int LiefereHoehe()
{
    return Convert.ToInt32(textBoxHoehe.Text);
}


Danke für die Tipps.

Ritze

Moderiert von user profile iconTh69: Code- durch C#-Tags ersetzt
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: Sa 18.10.14 16:35 
Hallo,

wird deine Unterform auch mit DialogResult.OK geschlossen, also wird der if-Block überhaupt betreten?
Bei den beiden int-Werten würde ich persönlich auf Properties zurückgreifen, also
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:
24:
25:
26:
27:
28:
29:
30:
class DeineUnterForm
{
    public int BildBreite
    {
        get
        {
            int val;
            if (int.TryParse(textBoxBreite.Text, out val)) return val;
            return -1;
        }
        set
        {
            textBoxBreite.Text = value.ToString();
        }
    }
  
    public int BildHoehe
    {
        get
        {
            int val;
            if (int.TryParse(textBoxHoehe.Text, out val)) return val;
            return -1;
        }
        set
        {
            textBoxHoehe.Text = value.ToString();
        }
    }
}

und dann in der Hauptform:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
...

if (FrageBildgroesse.DialogResult == DialogResult.OK)
      {
        pictureBox1.Width = FrageBildgroesse.BildBreite;
        pictureBox1.Height = FrageBildgroesse.BildHoehe;
      }

_________________
Der längste Typ-Name im .NET-Framework ist: ListViewVirtualItemsSelectionRangeChangedEventHandler
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4705
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Sa 18.10.14 17:24 
Wie ist die PictureBox eingestellt? Es gibt genug Einstellungen in denen setzen von Height und Width keinen Einfluss hat. Z.B Wenn du an der PictureBox entsprechende Anchors gesetzt hast oder das Docking unpassend gesetzt hast oder du den SizeMode auf AutoSize gesetzt hast oder oder oder.

Edit : Dock und Anchors ist wahrscheinlich Unsinn.
Ritzeratze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 101



BeitragVerfasst: So 19.10.14 10:41 
Moin,

Danke für den Tipp. Hat wunderbar geholfen.

@ Ralf: Die Eigenschaft der Picturebox musste noch modiofiziert werden. Stand wie vermutet auf Dock = Fill.


Gruss Ritze