مشاركة عبر


كيفية القيام بما يلي: تعديل الحجم أو الموضع من صورة في تشغيل الوقت (Windows Forms)

If you استخدم the Windows Forms PictureBox عنصر تحكم تشغيل a نموذج, you can التعيين the SizeMode خاصية تشغيل it إلى:

  • محاذاة the صورة's upper يسار corner مع the عنصر تحكم's upper يسار corner

  • مركز the صورة within the عنصر تحكم

  • ضبط حجم عنصر التحكم إلى احتواء وهي تعرض الصورة

  • تمدد أي صورة it displays للملاءمة the عنصر تحكم

Stretching نسخة (especially واحد في نسخة نقطية تنسيق) can produce a loss في نسخة جودة. سرد ملفات التعريف، وهي عبارة عن تعليمات الرسومات لرسم الصور في وقت التشغيل، يتم ملاءمة لتمديدها من تكون الصور النقطية.

إلى التعيين the SizeMode خاصية at تشغيل الوقت

  • التعيينSizeModeإلىNormal(the الافتراضي),AutoSize,CenterImage, أوStretchImage. Normal means that the نسخة هو placed في the عنصر تحكم's upper-يسار corner; if the نسخة هو بقعة صغيرة than the عنصر تحكم, its lower و يمين edges are clipped. CenterImage means that the نسخة هو centered within the عنصر تحكم; if the نسخة هو بقعة صغيرة than the عنصر تحكم, the نسخة's outside edges are clipped. AutoSize means that the الحجم of the عنصر تحكم هو adjusted إلى the الحجم of the نسخة. StretchImage هو the عكسى, و means that the الحجم of the نسخة هو adjusted إلى the الحجم of the عنصر تحكم.

    في المثال أدناه ، المسار المحدد لموقع الصورة هو مجلد المستندات. ويتم ذلك لأنه بإمكانك افتراض أن معظم أجهزة الكمبيوتر التي تستخدم نظام التشغيل Windows تشمل هذا الدليل. كما يتيح هذا لمستخدمين مستويات وصول الحد الأدنى للنظام من تشغيل التطبيق بأمان. المثال التالي يفترض وجود نموذج مع عنصر تحكم PictureBox تمت إضافة مسبقاً.

    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 Sub
    
    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.
       // 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.set_SizeMode(PictureBoxSizeMode.StretchImage);
       // Load the picture into the control.
       // You should replace "image.gif" in the sample below 
       // with an icon of your own choosing.
       pictureBox1.set_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"));
       }
    

راجع أيضًا:

المهام

كيفية: تحميل صورة باستخدام مصمم (نماذج Windows)

كيفية القيام بما يلي: تعيين الصور في وقت تشغيل (Windows Forms)

المرجع

PictureBox

مربع صورة عنصر تحكم نظرة عامة (Windows Forms)

موارد أخرى

عنصر تحكم مربع صورة (Windows Forms)