Anteckning
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Om du använder Windows Forms PictureBox-kontrollen i ett formulär kan du ange egenskapen SizeMode på det till:
Justera bildens övre vänstra hörn med kontrollens övre vänstra hörn
Centrera bilden inom kontrollen
Justera storleken på kontrollen så att den passar den bild som visas
Sträck ut alla bilder som visas för att passa kontrollen
Om du sträcker ut en bild (särskilt en i bitmappsformat) kan bildkvaliteten försämras. Metafiler, som är listor med grafikinstruktioner för att rita bilder vid körtid, passar bättre för sträckning än bitmappar.
Så här anger du egenskapen SizeMode vid körning
Ange SizeMode till Normal (standard), AutoSize, CenterImageeller StretchImage. Normal innebär att bilden placeras i kontrollens övre vänstra hörn. Om bilden är större än kontrollen klipps dess nedre och högra kanter bort. CenterImage innebär att avbildningen är centrerad i kontrollen. Om bilden är större än kontrollen klipps bildens yttre kanter av. AutoSize innebär att kontrollens storlek justeras till bildens storlek. StretchImage är det omvända och innebär att bildens storlek justeras till kontrollens storlek.
I exemplet nedan är sökvägen som angetts för platsen för avbildningen mappen Mina dokument. Detta görs eftersom du kan anta att de flesta datorer som kör Windows-operativsystemet innehåller den här katalogen. Detta gör det också möjligt för användare med minimala systemåtkomstnivåer att köra programmet på ett säkert sätt. Exemplet nedan förutsätter ett formulär med en PictureBox kontroll som redan har lagts till.
Private Sub StretchPic() ' Stretch the picture to fit the control. PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage ' Load the picture into the control. ' You should replace the bold image ' in the sample below with an icon of your own choosing. PictureBox1.Image = Image.FromFile _ (System.Environment.GetFolderPath _ (System.Environment.SpecialFolder.Personal) _ & "\Image.gif") End Subprivate void StretchPic(){ // Stretch the picture to fit the control. PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; // Load the picture into the control. // You should replace the bold image // in the sample below with an icon of your own choosing. // Note the escape character used (@) when specifying the path. PictureBox1.Image = Image.FromFile _ (System.Environment.GetFolderPath _ (System.Environment.SpecialFolder.Personal) _ + @"\Image.gif") }private: void StretchPic() { // Stretch the picture to fit the control. pictureBox1->SizeMode = PictureBoxSizeMode::StretchImage; // Load the picture into the control. // You should replace the bold image // in the sample below with an icon of your own choosing. pictureBox1->Image = Image::FromFile(String::Concat( System::Environment::GetFolderPath( System::Environment::SpecialFolder::Personal), "\\Image.gif")); }
Se även
.NET Desktop feedback