国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

在程序中動態地修改按鈕的圖片和尺寸

2023-05-10 18:49:25
字體:
來源:轉載
供稿:網友

下面的C#程序代碼演示了在程序中創建圖片按鈕,并指定其大小及其位置的方法。

注:本程序轉自國外的一個網站(http://www.java2s.com)。

using System;
using System.Drawing;
using System.Windows.Forms;
   
class BitmapButtons: Form
{
     int    cxBtn, cyBtn, dxBtn;
     Button btnLarger, btnSmaller;
   
     public static void Main()
     {
          Application.Run(new BitmapButtons());
     }
     public BitmapButtons()
     {
          ResizeRedraw = true;
   
          dxBtn = Font.Height;
          btnLarger = new Button();
          btnLarger.Parent = this;
          btnLarger.Image  = new Bitmap(GetType()"LargerButton.bmp";
   
          cxBtn = btnLarger.Image.Width  + 8;
          cyBtn = btnLarger.Image.Height + 8;
   
          btnLarger.Size   = new Size(cxBtn, cyBtn);
          btnLarger.Click += new EventHandler(ButtonLargerOnClick);
   
          btnSmaller = new Button();
          btnSmaller.Parent = this;
          btnSmaller.Image  = new Bitmap(GetType()"SmallerButton.bmp");
          btnSmaller.Size   = new Size(cxBtn, cyBtn);
          btnSmaller.Click += new EventHandler(ButtonSmallerOnClick);
   
          OnResize(EventArgs.Empty);
     }
     protected override void OnResize(EventArgs ea)
     {
          base.OnResize(ea);
   
          btnLarger.Location = new Point(ClientSize.Width / - cxBtn - dxBtn / 2,
                                  (ClientSize.Height - cyBtn2);
          btnSmaller.Location = new Point(ClientSize.Width / + dxBtn / 2,
                                  (ClientSize.Height - cyBtn2);
     }
     void ButtonLargerOnClick(object obj, EventArgs ea)
     {
          Left   = 50;
          Top    = 50;
          Width  = 50;
          Height = 50;
     }
     void ButtonSmallerOnClick(object obj, EventArgs ea)
     {
          Left   = 200;
          Top    = 200;
          Width  = 20;
          Height = 20;
     }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 虹口区| 泸西县| 本溪| 陇川县| 钟山县| 陕西省| 仙游县| 什邡市| 金华市| 台南市| 炎陵县| 乌苏市| 安吉县| 枣庄市| 当雄县| 杂多县| 综艺| 清水河县| 炉霍县| 永仁县| 吉隆县| 宁化县| 大姚县| 阿拉善盟| 古蔺县| 独山县| 土默特左旗| 东兰县| 吴旗县| 治多县| 承德市| 涞源县| 抚松县| 夹江县| 义乌市| 甘谷县| 皋兰县| 永康市| 青田县| 上杭县| 玉溪市|