Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
GeneralRe: Clicking a button with SendMessage Pin
Shameel31-May-11 0:58
professionalShameel31-May-11 0:58 
GeneralRe: Clicking a button with SendMessage Pin
musefan31-May-11 2:22
musefan31-May-11 2:22 
AnswerRe: Clicking a button with SendMessage Pin
Pete O'Hanlon31-May-11 2:43
mvePete O'Hanlon31-May-11 2:43 
GeneralRe: Clicking a button with SendMessage Pin
musefan31-May-11 5:59
musefan31-May-11 5:59 
AnswerRe: Clicking a button with SendMessage Pin
_Erik_1-Jun-11 4:20
_Erik_1-Jun-11 4:20 
QuestionRectangleF to and back from string? Pin
Chesnokov Yuriy30-May-11 22:49
professionalChesnokov Yuriy30-May-11 22:49 
AnswerRe: RectangleF to and back from string? Pin
Richard MacCutchan30-May-11 23:30
mveRichard MacCutchan30-May-11 23:30 
AnswerRe: RectangleF to and back from string? Pin
Pete O'Hanlon31-May-11 0:32
mvePete O'Hanlon31-May-11 0:32 
The following class could be used (with a bit of beefing up) to convert back from a string representation:
C#
namespace ParseRectangleF
{
  using System;
  using System.Drawing;

  public static class ParserUtility
  {
    /// <summary>
    /// Parse the input string into a valid RectangleF format.
    /// </summary>
    /// <param name="value">The string to convert into the RectangleF format.</param>
    /// <returns>The parsed rectangle.</returns>
    /// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is null or an empty string.</exception>
    /// <exception cref="ArgumentException">Thrown if the input string is not in a valid format.</exception>
    public static RectangleF Parse(string value)
    {
      if (string.IsNullOrEmpty(value))
        throw new ArgumentNullException(value);
      // Remove any { or } characters, as generated by the ToString() method.
      value = value.Replace("{", string.Empty).Replace("}", string.Empty).Replace(" ", string.Empty);
      var rectangle = new RectangleF();
      rectangle.X = GetValue(value, "X=");
      rectangle.Y = GetValue(value, "Y=");
      rectangle.Width = GetValue(value, "Width=");
      rectangle.Height = GetValue(value, "Height=");
      return rectangle;
    }

    /// <summary>
    /// Get the relevant value out of the input text and convert it into
    /// a float.
    /// </summary>
    /// <param name="value">The input string to retrieve the value from.</param>
    /// <param name="key">The key used to retrieve the value.</param>
    /// <returns>The value retrieved from the text.</returns>
    /// <exception cref="ArgumentException">Thrown if the input string is not in a valid format.</exception>
    private static float GetValue(string value, string key)
    {
      if (!key.EndsWith("="))
      {
        key += "=";
      }
      int ordinal = value.IndexOf(key, StringComparison.CurrentCultureIgnoreCase);
      int length = ordinal + key.Length;
      int commaPos = value.IndexOf(",", length);
      if (commaPos < length)
      {
        commaPos = value.Length;
      }
      string text = value.Substring(length, commaPos - length);

      float output;
      if (!float.TryParse(text, out output))
      {
        throw new ArgumentException(
          string.Format("The input {0} is not the right format for Parse. It should be formatted like X=nn, Y=, Width=nn, Height=nn.", value));
      }
      return output;
    }
  }
}
To call it, all you need to do is:
C#
RectangleF rect = ParserUtility.Parse("{x=10,  y=10,   width=100,height=300");

Forgive your enemies - it messes with their heads


My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility


QuestionRe: RectangleF to and back from string? Pin
Chesnokov Yuriy31-May-11 0:45
professionalChesnokov Yuriy31-May-11 0:45 
AnswerRe: RectangleF to and back from string? Pin
Pete O'Hanlon31-May-11 1:27
mvePete O'Hanlon31-May-11 1:27 
AnswerRe: RectangleF to and back from string? Pin
Chesnokov Yuriy31-May-11 1:54
professionalChesnokov Yuriy31-May-11 1:54 
GeneralRe: RectangleF to and back from string? Pin
Pete O'Hanlon31-May-11 2:36
mvePete O'Hanlon31-May-11 2:36 
AnswerRe: RectangleF to and back from string? [modified] Pin
DaveyM691-Jun-11 0:35
professionalDaveyM691-Jun-11 0:35 
QuestionSerialcomm dialing voice over modem Pin
Chuck Richards30-May-11 11:17
Chuck Richards30-May-11 11:17 
AnswerRe: Serialcomm dialing voice over modem Pin
Luc Pattyn30-May-11 12:25
sitebuilderLuc Pattyn30-May-11 12:25 
GeneralRe: Serialcomm dialing voice over modem Pin
Chuck Richards1-Jun-11 3:02
Chuck Richards1-Jun-11 3:02 
AnswerRe: Serialcomm dialing voice over modem Pin
Luc Pattyn1-Jun-11 3:13
sitebuilderLuc Pattyn1-Jun-11 3:13 
GeneralRe: Serialcomm dialing voice over modem Pin
Chuck Richards1-Jun-11 9:41
Chuck Richards1-Jun-11 9:41 
AnswerRe: Serialcomm dialing voice over modem Pin
Luc Pattyn1-Jun-11 14:12
sitebuilderLuc Pattyn1-Jun-11 14:12 
GeneralRe: Serialcomm dialing voice over modem Pin
Chuck Richards2-Jun-11 9:15
Chuck Richards2-Jun-11 9:15 
AnswerRe: Serialcomm dialing voice over modem Pin
Luc Pattyn2-Jun-11 9:31
sitebuilderLuc Pattyn2-Jun-11 9:31 
GeneralRe: Serialcomm dialing voice over modem Pin
Chuck Richards3-Jun-11 3:13
Chuck Richards3-Jun-11 3:13 
GeneralRe: Serialcomm dialing voice over modem Pin
Chuck Richards2-Jun-11 9:22
Chuck Richards2-Jun-11 9:22 
AnswerRe: Serialcomm dialing voice over modem [modified] Pin
Chuck Richards2-Jun-11 7:34
Chuck Richards2-Jun-11 7:34 
Questionproblem with calling folderbrowingDialog in a child thread. Pin
prasadbuddhika30-May-11 6:25
prasadbuddhika30-May-11 6:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.