|
 |
|
ใส่ตัวอักษรในภาพ แล้วทำให้เห็น Scroll bar ใน picture box อย่างไรครับ? |
|
 |
|
|
 |
 |
|
ผมกำลังโปรแกรมใส่ตัวหนังสือลงในรูปภาพ ซึ่งภาพจะย่อขยายตามจำนวนตัวอักษร แต่ติดตรงที่เวลาข้อความยาวๆ หลายๆบรรทัด รูปที่ได้จะเกินหน้าจอ แล้วจะมองไม่เห็นส่วนที่เกินออกไป ทำอย่างไรให้มี scrollbar ใน picture box ครับ?
ผมใส่โค้ด 2 บรรทัดในในอีเวนท์ onload หรือ onclick แล้วก็ยังไม่ได้ครับ (picture box อยู่ใน panel อีกทีครับ)
Code (C#)
this.panel1.AutoScroll = true;
this.picBox.SizeMode = PictureBoxSizeMode.AutoSize;
Code (C#)
private Bitmap CreateBitmapImage(string sImageText)
{
this.panel1.AutoScroll = true;
this.picBox.SizeMode = PictureBoxSizeMode.AutoSize;
SolidBrush brush = new SolidBrush(Color.FromArgb(FontColor));
string FileName = "", FilePath;
if (txtFileName.Text == "")
{
FileName = DateTime.Today.ToString("dd ") + DateTime.Today.ToString("MMMM ") + (DateTime.Today.Year + 543).ToString() + " " + DateTime.Now.ToString("HH") + DateTime.Now.ToString("mm") + DateTime.Now.ToString("ss");
}
else
FileName = txtFileName.Text;
FilePath = txtDirectoryPath.Text + "\\" + FileName + ".jpg";
Bitmap objBmpImage = new Bitmap(txtDirectoryPath.Text + "\\background.jpg");
int intWidth = 0;
int intHeight = 0;
// Create the Font object for the image text drawing.
Font objFont = new Font(FontName, FontSize, FontStyle.Regular, GraphicsUnit.Pixel);
switch (Fontstyle)
{
case "Regular": objFont = new Font(FontName, FontSize, FontStyle.Regular, GraphicsUnit.Pixel); break;
case "Bold": objFont = new Font(FontName, FontSize, FontStyle.Bold, GraphicsUnit.Pixel); break;
case "Italic": objFont = new Font(FontName, FontSize, FontStyle.Italic, GraphicsUnit.Pixel); break;
case "Underline": objFont = new Font(FontName, FontSize, FontStyle.Underline, GraphicsUnit.Pixel); break;
case "Bold, Italic": objFont = new Font(FontName, FontSize, FontStyle.Italic | FontStyle.Bold, GraphicsUnit.Pixel); break;
}
// Create a graphics object to measure the text's width and height.
Graphics objGraphics = Graphics.FromImage(objBmpImage);
// This is where the bitmap size is determined.
intWidth = (int)objGraphics.MeasureString(sImageText, objFont).Width + 15;
intHeight = (int)objGraphics.MeasureString(sImageText, objFont).Height + 15;
// Create the bmpImage again with the correct size for the text and font.
objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight));
StringFormat strFormat = new StringFormat();
switch(Alignment)
{
case "Left": strFormat.Alignment = StringAlignment.Near; break;
case "Center": strFormat.Alignment = StringAlignment.Center; break;
case "Right": strFormat.Alignment = StringAlignment.Far; break;
default: break;
}
switch (LineAlignment)
{
case "Top": strFormat.LineAlignment = StringAlignment.Near; break;
case "Center": strFormat.LineAlignment = StringAlignment.Center; break;
case "Bottom": strFormat.LineAlignment = StringAlignment.Far; break;
default: break;
}
// Add the colors to the new bitmap.
objGraphics = Graphics.FromImage(objBmpImage);
// Set Background color
if(rdoColorBack.Checked)
objGraphics.Clear(Color.FromArgb(BackgroundColor));
objGraphics.SmoothingMode = SmoothingMode.HighQuality;
//objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // <-- This is the correct value to use. ClearTypeGridFit is better yet!
objGraphics.DrawString(sImageText, objFont, brush, new RectangleF(0,0,intWidth,intHeight), strFormat /*StringFormat.GenericDefault*/);
objGraphics.Flush();
objBmpImage.Save(FilePath);
return (objBmpImage);
}
Tag : .NET, Win (Windows App), C#, VS 2010 (.NET 4.x), Windows

|
|
 |
 |
 |
 |
Date :
2013-03-12 13:31:33 |
By :
snowbell |
View :
1402 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอา picturebox ใส่ panel ด้วย dock แบบ fill
เวลามันล้นจะมี scroll bar ของ panel ให้เห็น
|
 |
 |
 |
 |
Date :
2013-03-12 16:34:12 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|