Autor Beitrag
joop
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Sa 13.09.14 21:10 
Hallo liebes Forum!
Ich möchte in mein Programm eine Zoom-Funktion einbauen, allerdings komme ich nicht so recht weiter.

Folgende Codezeilen habe ich bis jetzt:
ausblenden volle Höhe 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:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
        private void frmMain_WheelUsage(object sender, MouseEventArgs e)
        {
            if (Properties.Settings.Default.useScrollWheel == true)
            {
                if (e.Delta > 0) picBack();
                else if (e.Delta < 0) picForward();
            }
            else if (opened == true)
            {
                if (zoomed == false)
                {
                    pbMain.Dock = DockStyle.None;
                    pbMain.SizeMode = PictureBoxSizeMode.StretchImage;
                }
                pbMain.Size = getDimension();
                zoomed = true;
                pbMain.SendToBack();
                if (e.Delta > 0)
                {
                    int tempX = pbMain.Size.Width + 30;
                    int tempY = pbMain.Size.Height + 30;
                    int posX = pbMain.Location.X - 15;
                    int posY = pbMain.Location.Y - 15;
                    pbMain.Size = new Size(tempX, tempY);
                    pbMain.Location = new Point(posX, posY);
                }
                else if (e.Delta < 0)
                {
                    int tempX = pbMain.Size.Width - 30;
                    int tempY = pbMain.Size.Height - 30;
                    int posX = pbMain.Location.X + 15;
                    int posY = pbMain.Location.Y + 15;
                    pbMain.Size = new Size(tempX, tempY);
                    pbMain.Location = new Point(posX, posY);
                }
            }
        }


        Size getDimension()
        {
            if (pbMain.Image.Size.Width > pbMain.Size.Width || pbMain.Image.Size.Height > pbMain.Size.Height)
            {
                double dimension = (double)pbMain.Image.Size.Width / (double)pbMain.Image.Size.Height;
                double temp1 = (double)pbMain.Image.Size.Width / (double)pbMain.Size.Width;
                double temp2 = (double)pbMain.Image.Size.Height / (double)pbMain.Size.Height;

                if (temp1 > temp2) //Breite
                {
                    double breite = dimension * (double)pbMain.Size.Height;
                    return new Size((int)breite, pbMain.Size.Height);
                }
                else //Höhe
                {
                    double hoehe = (double)pbMain.Size.Width / dimension;
                    return new Size(pbMain.Size.Width, (int)hoehe);
                }
            }
            else
            {
                return new Size(pbMain.Image.Size.Width, pbMain.Image.Size.Height);
            }
        }


Wenn ich jetzt jedoch inzoomen will, geht das nicht, stattdessen verschiebt sich die PictureBox einfach ein Stück nach oben links.

Kann mir jemand sagen was ich falsch mache?

Vielen Dank im Voraus
MfG
Josef
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4799
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: So 14.09.14 09:19 
Hallo und :welcome:

welchen Wert hat denn die Eigenschaft PictureBox.SizeMode bei dir?
Es sollte auf StretchImage oder Zoom stehen.

Es ist aber eine ungewöhnliche Zoom-Funktionalität, daß sich die Größe der PictureBox verändern soll. Üblicherweise bedeutet Zoomen ja, daß man bei gleichbleibender Größe des Controls den Bild-Ausschnitt vergrößert anzeigt (mit weiterer Navigation für Bildausschnitt verschieben).