Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Translate language......

Translate language......

Scheduled Pinned Locked Moved ASP.NET
csharphelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Raymond Ooi
    wrote on last edited by
    #1

    Can someone help me to translate the VB code into C#? I can't get the Mid & Right function of VB in C#.. wonder how... Color.FromArgb(Val("&h" & Mid(RGBColor, 1, 2)), Val("&h" & Mid(RGBColor, 3, 2)), Val("&h" & Mid(RGBColor, 5, 2))) Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2) Million thanks....

    Richard DeemingR 1 Reply Last reply
    0
    • R Raymond Ooi

      Can someone help me to translate the VB code into C#? I can't get the Mid & Right function of VB in C#.. wonder how... Color.FromArgb(Val("&h" & Mid(RGBColor, 1, 2)), Val("&h" & Mid(RGBColor, 3, 2)), Val("&h" & Mid(RGBColor, 5, 2))) Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2) & Right("00" & Hex(Gray), 2) Million thanks....

      Richard DeemingR Online
      Richard DeemingR Online
      Richard Deeming
      wrote on last edited by
      #2

      The direct translation would be:

      using System.Globalization;
      ...
      Color c = Color.FromArgb(
      int.Parse(RGBColor.Substring(0, 2), NumberStyles.HexNumber),
      int.Parse(RGBColor.Substring(2, 2), NumberStyles.HexNumber),
      int.Parse(RGBColor.Substring(4, 2), NumberStyles.HexNumber));

      string s = Convert.ToString(c.R, 16).PadLeft(2, '0')
      + Convert.ToString(c.G, 16).PadLeft(2, '0')
      + Convert.ToString(c.B, 16).PadLeft(2, '0');

      A better solution would be to use the ColorTranslator class:

      Color c = ColorTranslator.FromHtml("#" + RGBColor);
      string s = ColorTranslator.ToHtml(c).Substring(1);


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups