PC Review


Reply
Thread Tools Rate Thread

Auto Size Lable to Text. How can i do this on CF2.0??

 
 
iKiLL
Guest
Posts: n/a
 
      12th Mar 2007
Hi All,

I am trying to Bulid Windows Mobile Forms Control with C# in VS2005 using
CF2.

On this control A lable is created and some text set for the control. My
problem is that i dont know how lond the text is going to be. so i need to
set the height and width of the label a cording to the data.

un fortunatly i have not been able to find a simple Auto Resize property
that will work so i have been trying to find a way to messure the string.
and calculat the number of lines that will be needed based on the Height of
the string and the max width of the label.

Below is my code.

The first heardal seems to be that CreateGraphics() Is not supported on the
Compact Framework.

Is there another way for me to get the lable to resize?

Thanks,
ink


CODE:


//this is the Working Width of the Slid Pannel
int iSliderWidth = pnSlide.Width - (m_iRight_Margin +
m_iLeft_Margin);

//Set up the Question Lable
Label oQuestionText = new Label();
oQuestionText.Top = m_iLine_Space;
oQuestionText.Left = m_iLeft_Margin;
oQuestionText.Font = new System.Drawing.Font(m_FontName,
m_FontSize, FontStyle.Bold);
oQuestionText.ForeColor = Color.Blue;

//Work out the Number of lines the Lable needs to be to fit
the text
Graphics g = picHidden.CreateGraphics(); //
Graphics.FromImage(img);
string sQuestionText =
oRowQA["syqu_questiontext"].ToString();
Font sFont = new Font(m_FontName, m_FontSize,
FontStyle.Bold);
// Measure string.
SizeF stringSize = new SizeF();
stringSize = g.MeasureString(sQuestionText, sFont);
int iStringWidth =
int.Parse(stringSize.Width.ToString("####0"));
float fNoOfLines = iStringWidth / iSliderWidth;
if (fNoOfLines > 1)
{
oQuestionText.Width = iSliderWidth;
//may seem silly but this makes sure the Math.Round
rounds up by always adding 0.5
oQuestionText.Height =
Convert.ToInt32(Math.Round((fNoOfLines *
int.Parse(stringSize.Height.ToString("####0"))) + 0.5));
}
else
{
oQuestionText.Width = iSliderWidth;
//may seem silly but this makes sure the Math.Round
rounds up by always adding 0.5
oQuestionText.Height =
Convert.ToInt32(Math.Round(int.Parse(stringSize.Height.ToString("####0")) +
0.5));
}
g.Dispose();

oQuestionText.Text = sQuestionText;
//Add the control to the slid panel
pnSlide.Controls.Add(oQuestionText);



 
Reply With Quote
 
 
 
 
Tomer Gabel
Guest
Posts: n/a
 
      12th Mar 2007
Hello iKiLL,

Graphics.MeasureString will return a SizeF construct you can use for that.

Regards,
Tomer Gabel (http://www.tomergabel.com)
Monfort Software Engineering Ltd. (http://www.monfort.co.il)


> Hi All,
>
> I am trying to Bulid Windows Mobile Forms Control with C# in VS2005
> using CF2.
>
> On this control A lable is created and some text set for the control.
> My problem is that i dont know how lond the text is going to be. so i
> need to set the height and width of the label a cording to the data.
>
> un fortunatly i have not been able to find a simple Auto Resize
> property that will work so i have been trying to find a way to messure
> the string. and calculat the number of lines that will be needed based
> on the Height of the string and the max width of the label.
>
> Below is my code.
>
> The first heardal seems to be that CreateGraphics() Is not supported
> on the Compact Framework.
>
> Is there another way for me to get the lable to resize?
>
> Thanks,
> ink
> CODE:
>
> //this is the Working Width of the Slid Pannel
> int iSliderWidth = pnSlide.Width - (m_iRight_Margin +
> m_iLeft_Margin);
> //Set up the Question Lable
> Label oQuestionText = new Label();
> oQuestionText.Top = m_iLine_Space;
> oQuestionText.Left = m_iLeft_Margin;
> oQuestionText.Font = new
> System.Drawing.Font(m_FontName,
> m_FontSize, FontStyle.Bold);
> oQuestionText.ForeColor = Color.Blue;
> //Work out the Number of lines the Lable needs to be
> to fit
> the text
> Graphics g = picHidden.CreateGraphics(); //
> Graphics.FromImage(img);
> string sQuestionText =
> oRowQA["syqu_questiontext"].ToString();
> Font sFont = new Font(m_FontName, m_FontSize,
> FontStyle.Bold);
> // Measure string.
> SizeF stringSize = new SizeF();
> stringSize = g.MeasureString(sQuestionText, sFont);
> int iStringWidth =
> int.Parse(stringSize.Width.ToString("####0"));
> float fNoOfLines = iStringWidth / iSliderWidth;
> if (fNoOfLines > 1)
> {
> oQuestionText.Width = iSliderWidth;
> //may seem silly but this makes sure the
> Math.Round
> rounds up by always adding 0.5
> oQuestionText.Height =
> Convert.ToInt32(Math.Round((fNoOfLines *
> int.Parse(stringSize.Height.ToString("####0"))) + 0.5));
> }
> else
> {
> oQuestionText.Width = iSliderWidth;
> //may seem silly but this makes sure the
> Math.Round
> rounds up by always adding 0.5
> oQuestionText.Height =
> Convert.ToInt32(Math.Round(int.Parse(stringSize.Height.ToString("####0
> ")) +
> 0.5));
> }
> g.Dispose();
> oQuestionText.Text = sQuestionText;
> //Add the control to the slid panel
> pnSlide.Controls.Add(oQuestionText);



 
Reply With Quote
 
iKiLL
Guest
Posts: n/a
 
      12th Mar 2007
Hi Tomer,

Thanks for you input.

If you take another look at the code attached you will see that i have
actualy got that.

The problem is before getting to that on the
Graphics g = picHidden.CreateGraphics();
Line of code.

You see CreateGraphics(); does not seem to be supported in the CF so i need
some other way of Creating a Graphic in my variable.

Do you have any ideas on how to do that?

Thanks,
ink



"Tomer Gabel" <tomer at tomergabel dot com> wrote in message
news:(E-Mail Removed)...
> Hello iKiLL,
>
> Graphics.MeasureString will return a SizeF construct you can use for that.
>
> Regards,
> Tomer Gabel (http://www.tomergabel.com)
> Monfort Software Engineering Ltd. (http://www.monfort.co.il)
>
>
>> Hi All,
>>
>> I am trying to Bulid Windows Mobile Forms Control with C# in VS2005
>> using CF2.
>>
>> On this control A lable is created and some text set for the control.
>> My problem is that i dont know how lond the text is going to be. so i
>> need to set the height and width of the label a cording to the data.
>>
>> un fortunatly i have not been able to find a simple Auto Resize
>> property that will work so i have been trying to find a way to messure
>> the string. and calculat the number of lines that will be needed based
>> on the Height of the string and the max width of the label.
>>
>> Below is my code.
>>
>> The first heardal seems to be that CreateGraphics() Is not supported
>> on the Compact Framework.
>>
>> Is there another way for me to get the lable to resize?
>>
>> Thanks,
>> ink
>> CODE:
>>
>> //this is the Working Width of the Slid Pannel
>> int iSliderWidth = pnSlide.Width - (m_iRight_Margin +
>> m_iLeft_Margin);
>> //Set up the Question Lable
>> Label oQuestionText = new Label();
>> oQuestionText.Top = m_iLine_Space;
>> oQuestionText.Left = m_iLeft_Margin;
>> oQuestionText.Font = new
>> System.Drawing.Font(m_FontName,
>> m_FontSize, FontStyle.Bold);
>> oQuestionText.ForeColor = Color.Blue;
>> //Work out the Number of lines the Lable needs to be
>> to fit
>> the text
>> Graphics g = picHidden.CreateGraphics(); //
>> Graphics.FromImage(img);
>> string sQuestionText =
>> oRowQA["syqu_questiontext"].ToString();
>> Font sFont = new Font(m_FontName, m_FontSize,
>> FontStyle.Bold);
>> // Measure string.
>> SizeF stringSize = new SizeF();
>> stringSize = g.MeasureString(sQuestionText, sFont);
>> int iStringWidth =
>> int.Parse(stringSize.Width.ToString("####0"));
>> float fNoOfLines = iStringWidth / iSliderWidth;
>> if (fNoOfLines > 1)
>> {
>> oQuestionText.Width = iSliderWidth;
>> //may seem silly but this makes sure the
>> Math.Round
>> rounds up by always adding 0.5
>> oQuestionText.Height =
>> Convert.ToInt32(Math.Round((fNoOfLines *
>> int.Parse(stringSize.Height.ToString("####0"))) + 0.5));
>> }
>> else
>> {
>> oQuestionText.Width = iSliderWidth;
>> //may seem silly but this makes sure the
>> Math.Round
>> rounds up by always adding 0.5
>> oQuestionText.Height =
>> Convert.ToInt32(Math.Round(int.Parse(stringSize.Height.ToString("####0
>> ")) +
>> 0.5));
>> }
>> g.Dispose();
>> oQuestionText.Text = sQuestionText;
>> //Add the control to the slid panel
>> pnSlide.Controls.Add(oQuestionText);

>
>



 
Reply With Quote
 
iKiLL
Guest
Posts: n/a
 
      12th Mar 2007
Looks like i found a way that works.

//Work out the Number of lines the Lable needs to be to fit the text
Bitmap bmp = new Bitmap(175, 175);
Graphics g = Graphics.FromImage(bmp);

I also found a Auto Resizing label class.

Here:
http://weblogs.asp.net/okloeten/arch...30/103384.aspx

Hope this helps some one else to.

ink








"iKiLL" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Tomer,
>
> Thanks for you input.
>
> If you take another look at the code attached you will see that i have
> actualy got that.
>
> The problem is before getting to that on the
> Graphics g = picHidden.CreateGraphics();
> Line of code.
>
> You see CreateGraphics(); does not seem to be supported in the CF so i
> need some other way of Creating a Graphic in my variable.
>
> Do you have any ideas on how to do that?
>
> Thanks,
> ink
>
>
>
> "Tomer Gabel" <tomer at tomergabel dot com> wrote in message
> news:(E-Mail Removed)...
>> Hello iKiLL,
>>
>> Graphics.MeasureString will return a SizeF construct you can use for
>> that.
>>
>> Regards,
>> Tomer Gabel (http://www.tomergabel.com)
>> Monfort Software Engineering Ltd. (http://www.monfort.co.il)
>>
>>
>>> Hi All,
>>>
>>> I am trying to Bulid Windows Mobile Forms Control with C# in VS2005
>>> using CF2.
>>>
>>> On this control A lable is created and some text set for the control.
>>> My problem is that i dont know how lond the text is going to be. so i
>>> need to set the height and width of the label a cording to the data.
>>>
>>> un fortunatly i have not been able to find a simple Auto Resize
>>> property that will work so i have been trying to find a way to messure
>>> the string. and calculat the number of lines that will be needed based
>>> on the Height of the string and the max width of the label.
>>>
>>> Below is my code.
>>>
>>> The first heardal seems to be that CreateGraphics() Is not supported
>>> on the Compact Framework.
>>>
>>> Is there another way for me to get the lable to resize?
>>>
>>> Thanks,
>>> ink
>>> CODE:
>>>
>>> //this is the Working Width of the Slid Pannel
>>> int iSliderWidth = pnSlide.Width - (m_iRight_Margin +
>>> m_iLeft_Margin);
>>> //Set up the Question Lable
>>> Label oQuestionText = new Label();
>>> oQuestionText.Top = m_iLine_Space;
>>> oQuestionText.Left = m_iLeft_Margin;
>>> oQuestionText.Font = new
>>> System.Drawing.Font(m_FontName,
>>> m_FontSize, FontStyle.Bold);
>>> oQuestionText.ForeColor = Color.Blue;
>>> //Work out the Number of lines the Lable needs to be
>>> to fit
>>> the text
>>> Graphics g = picHidden.CreateGraphics(); //
>>> Graphics.FromImage(img);
>>> string sQuestionText =
>>> oRowQA["syqu_questiontext"].ToString();
>>> Font sFont = new Font(m_FontName, m_FontSize,
>>> FontStyle.Bold);
>>> // Measure string.
>>> SizeF stringSize = new SizeF();
>>> stringSize = g.MeasureString(sQuestionText, sFont);
>>> int iStringWidth =
>>> int.Parse(stringSize.Width.ToString("####0"));
>>> float fNoOfLines = iStringWidth / iSliderWidth;
>>> if (fNoOfLines > 1)
>>> {
>>> oQuestionText.Width = iSliderWidth;
>>> //may seem silly but this makes sure the
>>> Math.Round
>>> rounds up by always adding 0.5
>>> oQuestionText.Height =
>>> Convert.ToInt32(Math.Round((fNoOfLines *
>>> int.Parse(stringSize.Height.ToString("####0"))) + 0.5));
>>> }
>>> else
>>> {
>>> oQuestionText.Width = iSliderWidth;
>>> //may seem silly but this makes sure the
>>> Math.Round
>>> rounds up by always adding 0.5
>>> oQuestionText.Height =
>>> Convert.ToInt32(Math.Round(int.Parse(stringSize.Height.ToString("####0
>>> ")) +
>>> 0.5));
>>> }
>>> g.Dispose();
>>> oQuestionText.Text = sQuestionText;
>>> //Add the control to the slid panel
>>> pnSlide.Controls.Add(oQuestionText);

>>
>>

>
>



 
Reply With Quote
 
Guest
Posts: n/a
 
      12th Mar 2007
CreateGraphics is supported IIRC for Form, Control and Panel only. Use one
of those or override OnPaint.


--
Chris Tacke - Embedded MVP
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


"iKiLL" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Tomer,
>
> Thanks for you input.
>
> If you take another look at the code attached you will see that i have
> actualy got that.
>
> The problem is before getting to that on the
> Graphics g = picHidden.CreateGraphics();
> Line of code.
>
> You see CreateGraphics(); does not seem to be supported in the CF so i
> need some other way of Creating a Graphic in my variable.
>
> Do you have any ideas on how to do that?
>
> Thanks,
> ink
>
>
>
> "Tomer Gabel" <tomer at tomergabel dot com> wrote in message
> news:(E-Mail Removed)...
>> Hello iKiLL,
>>
>> Graphics.MeasureString will return a SizeF construct you can use for
>> that.
>>
>> Regards,
>> Tomer Gabel (http://www.tomergabel.com)
>> Monfort Software Engineering Ltd. (http://www.monfort.co.il)
>>
>>
>>> Hi All,
>>>
>>> I am trying to Bulid Windows Mobile Forms Control with C# in VS2005
>>> using CF2.
>>>
>>> On this control A lable is created and some text set for the control.
>>> My problem is that i dont know how lond the text is going to be. so i
>>> need to set the height and width of the label a cording to the data.
>>>
>>> un fortunatly i have not been able to find a simple Auto Resize
>>> property that will work so i have been trying to find a way to messure
>>> the string. and calculat the number of lines that will be needed based
>>> on the Height of the string and the max width of the label.
>>>
>>> Below is my code.
>>>
>>> The first heardal seems to be that CreateGraphics() Is not supported
>>> on the Compact Framework.
>>>
>>> Is there another way for me to get the lable to resize?
>>>
>>> Thanks,
>>> ink
>>> CODE:
>>>
>>> //this is the Working Width of the Slid Pannel
>>> int iSliderWidth = pnSlide.Width - (m_iRight_Margin +
>>> m_iLeft_Margin);
>>> //Set up the Question Lable
>>> Label oQuestionText = new Label();
>>> oQuestionText.Top = m_iLine_Space;
>>> oQuestionText.Left = m_iLeft_Margin;
>>> oQuestionText.Font = new
>>> System.Drawing.Font(m_FontName,
>>> m_FontSize, FontStyle.Bold);
>>> oQuestionText.ForeColor = Color.Blue;
>>> //Work out the Number of lines the Lable needs to be
>>> to fit
>>> the text
>>> Graphics g = picHidden.CreateGraphics(); //
>>> Graphics.FromImage(img);
>>> string sQuestionText =
>>> oRowQA["syqu_questiontext"].ToString();
>>> Font sFont = new Font(m_FontName, m_FontSize,
>>> FontStyle.Bold);
>>> // Measure string.
>>> SizeF stringSize = new SizeF();
>>> stringSize = g.MeasureString(sQuestionText, sFont);
>>> int iStringWidth =
>>> int.Parse(stringSize.Width.ToString("####0"));
>>> float fNoOfLines = iStringWidth / iSliderWidth;
>>> if (fNoOfLines > 1)
>>> {
>>> oQuestionText.Width = iSliderWidth;
>>> //may seem silly but this makes sure the
>>> Math.Round
>>> rounds up by always adding 0.5
>>> oQuestionText.Height =
>>> Convert.ToInt32(Math.Round((fNoOfLines *
>>> int.Parse(stringSize.Height.ToString("####0"))) + 0.5));
>>> }
>>> else
>>> {
>>> oQuestionText.Width = iSliderWidth;
>>> //may seem silly but this makes sure the
>>> Math.Round
>>> rounds up by always adding 0.5
>>> oQuestionText.Height =
>>> Convert.ToInt32(Math.Round(int.Parse(stringSize.Height.ToString("####0
>>> ")) +
>>> 0.5));
>>> }
>>> g.Dispose();
>>> oQuestionText.Text = sQuestionText;
>>> //Add the control to the slid panel
>>> pnSlide.Controls.Add(oQuestionText);

>>
>>

>
>



 
Reply With Quote
 
iKiLL
Guest
Posts: n/a
 
      12th Mar 2007
Hi

i am sorry but i don't know what IIRC means.
I tried using the Panel as well as a test and it was definatly not in the
Context help for it as a method.

But i have solved the problem now using the Bitmap Object.

thanks,

ink



"<ctacke/>" <ctacke[@]opennetcf[dot]com> wrote in message
news:(E-Mail Removed)...
> CreateGraphics is supported IIRC for Form, Control and Panel only. Use
> one of those or override OnPaint.
>
>
> --
> Chris Tacke - Embedded MVP
> OpenNETCF Consulting
> Managed Code in the Embedded World
> www.opennetcf.com
> --
>
>
> "iKiLL" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi Tomer,
>>
>> Thanks for you input.
>>
>> If you take another look at the code attached you will see that i have
>> actualy got that.
>>
>> The problem is before getting to that on the
>> Graphics g = picHidden.CreateGraphics();
>> Line of code.
>>
>> You see CreateGraphics(); does not seem to be supported in the CF so i
>> need some other way of Creating a Graphic in my variable.
>>
>> Do you have any ideas on how to do that?
>>
>> Thanks,
>> ink
>>
>>
>>
>> "Tomer Gabel" <tomer at tomergabel dot com> wrote in message
>> news:(E-Mail Removed)...
>>> Hello iKiLL,
>>>
>>> Graphics.MeasureString will return a SizeF construct you can use for
>>> that.
>>>
>>> Regards,
>>> Tomer Gabel (http://www.tomergabel.com)
>>> Monfort Software Engineering Ltd. (http://www.monfort.co.il)
>>>
>>>
>>>> Hi All,
>>>>
>>>> I am trying to Bulid Windows Mobile Forms Control with C# in VS2005
>>>> using CF2.
>>>>
>>>> On this control A lable is created and some text set for the control.
>>>> My problem is that i dont know how lond the text is going to be. so i
>>>> need to set the height and width of the label a cording to the data.
>>>>
>>>> un fortunatly i have not been able to find a simple Auto Resize
>>>> property that will work so i have been trying to find a way to messure
>>>> the string. and calculat the number of lines that will be needed based
>>>> on the Height of the string and the max width of the label.
>>>>
>>>> Below is my code.
>>>>
>>>> The first heardal seems to be that CreateGraphics() Is not supported
>>>> on the Compact Framework.
>>>>
>>>> Is there another way for me to get the lable to resize?
>>>>
>>>> Thanks,
>>>> ink
>>>> CODE:
>>>>
>>>> //this is the Working Width of the Slid Pannel
>>>> int iSliderWidth = pnSlide.Width - (m_iRight_Margin +
>>>> m_iLeft_Margin);
>>>> //Set up the Question Lable
>>>> Label oQuestionText = new Label();
>>>> oQuestionText.Top = m_iLine_Space;
>>>> oQuestionText.Left = m_iLeft_Margin;
>>>> oQuestionText.Font = new
>>>> System.Drawing.Font(m_FontName,
>>>> m_FontSize, FontStyle.Bold);
>>>> oQuestionText.ForeColor = Color.Blue;
>>>> //Work out the Number of lines the Lable needs to be
>>>> to fit
>>>> the text
>>>> Graphics g = picHidden.CreateGraphics(); //
>>>> Graphics.FromImage(img);
>>>> string sQuestionText =
>>>> oRowQA["syqu_questiontext"].ToString();
>>>> Font sFont = new Font(m_FontName, m_FontSize,
>>>> FontStyle.Bold);
>>>> // Measure string.
>>>> SizeF stringSize = new SizeF();
>>>> stringSize = g.MeasureString(sQuestionText, sFont);
>>>> int iStringWidth =
>>>> int.Parse(stringSize.Width.ToString("####0"));
>>>> float fNoOfLines = iStringWidth / iSliderWidth;
>>>> if (fNoOfLines > 1)
>>>> {
>>>> oQuestionText.Width = iSliderWidth;
>>>> //may seem silly but this makes sure the
>>>> Math.Round
>>>> rounds up by always adding 0.5
>>>> oQuestionText.Height =
>>>> Convert.ToInt32(Math.Round((fNoOfLines *
>>>> int.Parse(stringSize.Height.ToString("####0"))) + 0.5));
>>>> }
>>>> else
>>>> {
>>>> oQuestionText.Width = iSliderWidth;
>>>> //may seem silly but this makes sure the
>>>> Math.Round
>>>> rounds up by always adding 0.5
>>>> oQuestionText.Height =
>>>> Convert.ToInt32(Math.Round(int.Parse(stringSize.Height.ToString("####0
>>>> ")) +
>>>> 0.5));
>>>> }
>>>> g.Dispose();
>>>> oQuestionText.Text = sQuestionText;
>>>> //Add the control to the slid panel
>>>> pnSlide.Controls.Add(oQuestionText);
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I reduce the size of the font in the return address lable. Isidor Microsoft Word Document Management 1 2nd Mar 2009 07:08 AM
How do I place downloaded lable templates into word lable wizzard =?Utf-8?B?U2FkaWU=?= Microsoft Word Document Management 1 13th Apr 2007 12:05 AM
Auto Size Lable to Text. How can i do this on CF2.0?? iKiLL Microsoft C# .NET 5 12th Mar 2007 02:59 PM
accurate lable size =?Utf-8?B?TEFCRUwgU0laRQ==?= Microsoft Access Queries 1 6th Jan 2005 06:58 AM
AUTO LABLE - Color those who create/modify Standish Microsoft Outlook Calendar 1 28th Jul 2004 05:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:22 PM.