我想在文本的左侧显示图像,但我还希望图像适合按钮(不大于按钮或太小)。似乎有两个选项:BackgroundImage
和Image
属性。
如果我使用BackgroundImage
,我可以使图像适合按钮大小,但图像似乎总是放在中心。如果我使用Image
,我可以将图像放在文本的左侧,但是图像不适合按钮。
有没有办法同时获得两者?
根据要求,我附上了源代码。我刚刚使用了GUI设计器,代码是由它生成的,所以它包含很多行。简而言之,我使用Background
制作前两个按钮,使用Image
制作底部的两个按钮。
//
// button2
//
this.button2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.button2.Image = global::delete_menu.Properties.Resources.folder;
this.button2.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.button2.Location = new System.Drawing.Point(63, 158);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(118, 25);
this.button2.TabIndex = 0;
this.button2.Text = "image";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button1_Click);
//
// button1
//
this.button1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button1.BackgroundImage")));
this.button1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.button1.ContextMenuStrip = this.contextMenuStrip1;
this.button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.button1.Location = new System.Drawing.Point(204, 63);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(245, 56);
this.button1.TabIndex = 0;
this.button1.Text = "background";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button3
//
this.button3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.button3.Image = global::delete_menu.Properties.Resources.folder;
this.button3.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.button3.Location = new System.Drawing.Point(204, 158);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(245, 56);
this.button3.TabIndex = 0;
this.button3.Text = "image";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button1_Click);
//
// button4
//
this.button4.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button4.BackgroundImage")));
this.button4.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.button4.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.button4.Location = new System.Drawing.Point(63, 63);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(118, 25);
this.button4.TabIndex = 0;
this.button4.Text = "background";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(505, 278);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button4);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.contextMenuStrip1.ResumeLayout(false);
this.ResumeLayout(false);