本文整理汇总了C#中System.Drawing.ColorConverter.ConvertFrom方法的典型用法代码示例。如果您正苦于以下问题:C# ColorConverter.ConvertFrom方法的具体用法?C# ColorConverter.ConvertFrom怎么用?C# ColorConverter.ConvertFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.ColorConverter
的用法示例。
在下文中一共展示了ColorConverter.ConvertFrom方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load( Object sender, EventArgs e )
{
// public attributes
if( BannerTypeId == "" )
{
BannerTypeId = "1"; // banner
}
if( BannerCount == "" )
{
BannerCount = "1";
}
if( PortalSettings.BannerAdvertising != 0 )
{
int intPortalId;
if( PortalSettings.BannerAdvertising == 1 )
{
intPortalId = PortalSettings.PortalId; // portal
}
else
{
intPortalId = Null.NullInteger; // host
}
// load banners
BannerController objBanners = new BannerController();
ArrayList arrBanners = objBanners.LoadBanners(intPortalId, Null.NullInteger, Int32.Parse(BannerTypeId), GroupName, Int32.Parse(BannerCount));
if( arrBanners.Count == 0 )
{
if( BannerTypeId == "1" )
{
// add default banner if none found
BannerInfo objBanner = new BannerInfo();
objBanner.BannerId = - 1;
objBanner.ImageFile = Globals.ApplicationPath + "/images/banner.gif";
objBanner.URL = Globals.GetDomainName(Request);
objBanner.BannerName = Localization.GetString( "Banner", Localization.GetResourceFile( this, MyFileName ) );
arrBanners.Add( objBanner );
}
}
// bind to datalist
lstBanners.DataSource = arrBanners;
lstBanners.DataBind();
// set banner display characteristics
if( lstBanners.Items.Count != 0 )
{
// container attributes
lstBanners.RepeatLayout = RepeatLayout.Table;
if( !String.IsNullOrEmpty(Width) )
{
lstBanners.Width = Unit.Parse( Width + "px" );
}
if( lstBanners.Items.Count == 1 )
{
lstBanners.CellPadding = 0;
lstBanners.CellSpacing = 0;
}
else
{
lstBanners.CellPadding = 4;
lstBanners.CellSpacing = 0;
}
if( !String.IsNullOrEmpty(Orientation) )
{
switch( Orientation )
{
case "H":
lstBanners.RepeatDirection = RepeatDirection.Horizontal;
break;
case "V":
lstBanners.RepeatDirection = RepeatDirection.Vertical;
break;
}
}
else
{
lstBanners.RepeatDirection = RepeatDirection.Vertical;
}
if( !String.IsNullOrEmpty(BorderWidth) )
{
lstBanners.ItemStyle.BorderWidth = Unit.Parse( BorderWidth + "px" );
}
if( !String.IsNullOrEmpty(BorderColor) )
{
ColorConverter objColorConverter = new ColorConverter();
lstBanners.ItemStyle.BorderColor = (Color)objColorConverter.ConvertFrom( BorderColor );
}
// item attributes
lstBanners.ItemStyle.VerticalAlign = VerticalAlign.Middle;
if( !String.IsNullOrEmpty(RowHeight) )
{
lstBanners.ItemStyle.Height = Unit.Parse( RowHeight + "px" );
//.........这里部分代码省略.........
示例2: OnLoad
/// <summary>
/// The Page_Load event handler on this User Control is used to
/// obtain a DataReader of banner information from the Banners
/// table, and then databind the results to a templated DataList
/// server control. It uses the DotNetNuke.BannerDB()
/// data component to encapsulate all data functionality.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks></remarks>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//exit without displaying banners to crawlers
if (Request.Browser.Crawler)
{
return;
}
try
{
int intPortalId = 0;
int intBannerTypeId = 0;
string strBannerGroup;
int intBanners = 0;
//banner parameters
switch (Convert.ToString(Settings["bannersource"]))
{
case "L": //local
case "":
intPortalId = PortalId;
break;
case "G": //global
intPortalId = Null.NullInteger;
break;
}
if (!String.IsNullOrEmpty(Convert.ToString(Settings["bannertype"])))
{
intBannerTypeId = Int32.Parse(Convert.ToString(Settings["bannertype"]));
}
strBannerGroup = Convert.ToString(Settings["bannergroup"]);
if (!String.IsNullOrEmpty(Convert.ToString(Settings["bannercount"])))
{
intBanners = Int32.Parse(Convert.ToString(Settings["bannercount"]));
}
if (!String.IsNullOrEmpty(Convert.ToString(Settings["padding"])))
{
lstBanners.CellPadding = Int32.Parse(Convert.ToString(Settings["padding"]));
}
//load banners
if (intBanners != 0)
{
var objBanners = new BannerController();
lstBanners.DataSource = objBanners.LoadBanners(intPortalId, ModuleId, intBannerTypeId, strBannerGroup, intBanners);
lstBanners.DataBind();
}
//set banner display characteristics
if (lstBanners.Items.Count != 0)
{
//container attributes
lstBanners.RepeatLayout = RepeatLayout.Table;
if (!String.IsNullOrEmpty(Convert.ToString(Settings["orientation"])))
{
switch (Convert.ToString(Settings["orientation"]))
{
case "H":
lstBanners.RepeatDirection = RepeatDirection.Horizontal;
break;
case "V":
lstBanners.RepeatDirection = RepeatDirection.Vertical;
break;
}
}
else
{
lstBanners.RepeatDirection = RepeatDirection.Vertical;
}
if (!String.IsNullOrEmpty(Convert.ToString(Settings["border"])))
{
lstBanners.ItemStyle.BorderWidth = Unit.Parse(Convert.ToString(Settings["border"]) + "px");
}
if (!String.IsNullOrEmpty(Convert.ToString(Settings["bordercolor"])))
{
var objColorConverter = new ColorConverter();
lstBanners.ItemStyle.BorderColor = (Color) objColorConverter.ConvertFrom(Convert.ToString(Settings["bordercolor"]));
}
//item attributes
if (!String.IsNullOrEmpty(Convert.ToString(Settings["rowheight"])))
{
lstBanners.ItemStyle.Height = Unit.Parse(Convert.ToString(Settings["rowheight"]) + "px");
}
if (!String.IsNullOrEmpty(Convert.ToString(Settings["colwidth"])))
{
lstBanners.ItemStyle.Width = Unit.Parse(Convert.ToString(Settings["colwidth"]) + "px");
}
}
//.........这里部分代码省略.........
示例3: OnLoad
//.........这里部分代码省略.........
GroupName = PortalController.GetPortalSetting("BannerGroupName", PortalSettings.PortalId, "");
}
if (String.IsNullOrEmpty(BannerCount))
{
BannerCount = "1";
}
int intPortalId;
if (PortalSettings.BannerAdvertising == 1)
{
intPortalId = PortalSettings.PortalId; //portal
}
else
{
intPortalId = Null.NullInteger; //host
}
//load banners
var objBanners = new BannerController();
ArrayList arrBanners = objBanners.LoadBanners(intPortalId, Null.NullInteger, BannerType, GroupName, int.Parse(BannerCount));
//bind to datalist
lstBanners.DataSource = arrBanners;
lstBanners.DataBind();
//set banner display characteristics
if (lstBanners.Items.Count != 0)
{
lstBanners.RepeatLayout = BannerLayout;
if (!String.IsNullOrEmpty(Width))
{
lstBanners.Width = Unit.Parse(Width + "px");
}
if(BannerColumns > 0)
{
lstBanners.RepeatColumns = BannerColumns;
}
if(BannerCellPadding > 0)
{
lstBanners.CellPadding = BannerCellPadding;
}
else
{
lstBanners.CellPadding = lstBanners.Items.Count == 1 ? 0 : 4;
}
lstBanners.CellSpacing = BannerCellSpacing;
if (!String.IsNullOrEmpty(Orientation))
{
switch (Orientation)
{
case "H":
lstBanners.RepeatDirection = RepeatDirection.Horizontal;
break;
case "V":
lstBanners.RepeatDirection = RepeatDirection.Vertical;
break;
}
}
else
{
lstBanners.RepeatDirection = RepeatDirection.Vertical;
}
if (!String.IsNullOrEmpty(BorderWidth))
{
lstBanners.ItemStyle.BorderWidth = Unit.Parse(BorderWidth + "px");
}
if (!String.IsNullOrEmpty(BorderColor))
{
var objColorConverter = new ColorConverter();
lstBanners.ItemStyle.BorderColor = (Color) objColorConverter.ConvertFrom(BorderColor);
}
//item attributes
if (!String.IsNullOrEmpty(RowHeight))
{
lstBanners.ItemStyle.Height = Unit.Parse(RowHeight + "px");
}
if (!String.IsNullOrEmpty(ColWidth))
{
lstBanners.ItemStyle.Width = Unit.Parse(ColWidth + "px");
}
}
else
{
lstBanners.Visible = false;
}
}
else
{
lstBanners.Visible = false;
}
}
示例4: ConvertFrom_NullCulture
public void ConvertFrom_NullCulture()
{
var conv = new ColorConverter();
var color = (Color) conv.ConvertFrom(null, null, "#0x23190A44");
Assert.Equal(35, color.A);
Assert.Equal(25, color.R);
Assert.Equal(10, color.G);
Assert.Equal(68, color.B);
}
示例5: ConvertFrom
public void ConvertFrom(int a, int r, int g, int b)
{
var conv = new ColorConverter();
Color color = (Color) conv.ConvertFrom(null, CultureInfo.InvariantCulture, $"#0x{a:x2}{r:x2}{g:x2}{b:x2}");
Assert.Equal(a, color.A);
Assert.Equal(r, color.R);
Assert.Equal(g, color.G);
Assert.Equal(b, color.B);
Assert.Equal(color,
(Color) conv.ConvertFrom(null, CultureInfo.InvariantCulture, $"#0X{a:x2}{r:x2}{g:x2}{b:x2}"));
Assert.Equal(color,
(Color) conv.ConvertFrom(null, CultureInfo.InvariantCulture, $"0x{a:x2}{r:x2}{g:x2}{b:x2}"));
Assert.Equal(color,
(Color) conv.ConvertFrom(null, CultureInfo.InvariantCulture, $"0X{a:x2}{r:x2}{g:x2}{b:x2}"));
}
示例6: ConvertFrom_Exception
public void ConvertFrom_Exception(string value)
{
var conv = new ColorConverter();
Assert.Throws<Exception>(() =>
{
conv.ConvertFrom(null, CultureInfo.InvariantCulture, value);
});
}
示例7: ConvertFrom_NotSupportedException
public void ConvertFrom_NotSupportedException(object value)
{
var conv = new ColorConverter();
Assert.Throws<NotSupportedException>(() =>
{
conv.ConvertFrom(null, CultureInfo.InvariantCulture, value);
});
}
示例8: ConvertFrom_Name
public void ConvertFrom_Name(string name)
{
var conv = new ColorConverter();
var color = Color.FromName(name);
Assert.Equal(color, (Color) conv.ConvertFrom(name));
Assert.Equal(color, (Color) conv.ConvertFrom(" " + name + " "));
}
示例9: ConvertFrom_Empty
public void ConvertFrom_Empty()
{
var conv = new ColorConverter();
var color = Color.Empty;
Assert.Equal(color, (Color) conv.ConvertFrom(string.Empty));
Assert.Equal(color, (Color) conv.ConvertFrom(" "));
}
示例10: ConvertFrom_FrFrSeparator
public void ConvertFrom_FrFrSeparator(int a, int r, int g, int b)
{
var conv = new ColorConverter();
var culture = new CultureInfo("fr-FR");
var color =
(Color)
conv.ConvertFrom(null, culture,
string.Format("{0}{4} {1}{4} {2}{4} {3}", a, r, g, b,
culture.TextInfo.ListSeparator));
Assert.Equal(a, color.A);
Assert.Equal(r, color.R);
Assert.Equal(g, color.G);
Assert.Equal(b, color.B);
}
示例11: Main
static void Main(string[] args)
{
for (int ii = 0; ii < args.Length && args[ii][0] == '-'; ++ii)
{
if (args[ii].Equals("-html") && ii + 1 < args.Length)
{
htmlfn = args[++ii];
}
else if (args[ii].Equals("-width") && ii + 1 < args.Length)
{
try
{
ww = Convert.ToInt32(args[++ii]);
}
catch { }
}
else if (args[ii].Equals("-height") && ii + 1 < args.Length)
{
try
{
hh = Convert.ToInt32(args[++ii]);
}
catch { }
}
else if (args[ii].Equals("-bgcolor") && ii + 1 < args.Length)
{
try
{
ColorConverter converter = new ColorConverter();
bgcolor = (Color)converter.ConvertFrom(args[++ii]);
}
catch { }
}
}
Application.Run(new Form1());
}
示例12: RenderGeneratedButton
/// <summary>
/// Rendering of a generated image button
/// </summary>
/// <param name="writer">The writer to render the html to</param>
private void RenderGeneratedButton(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Type, "image");
if (ImageAlign != ImageAlign.NotSet)
writer.AddAttribute(HtmlTextWriterAttribute.Align, ImageAlign.ToString());
Size size = new Size();
bool writeWidth = true;
bool writeHeight = true;
if (!this.Width.IsEmpty)
{
size.Width = (int)this.Width.Value;
writeWidth = false;
}
else if (Style["width"] != null)
{
int width;
if (int.TryParse(Style["width"].Replace("px", ""), out width))
size.Width = width;
writeWidth = false;
}
if (!this.Height.IsEmpty)
{
size.Height = (int)this.Height.Value;
writeHeight = false;
}
else if (Style["height"] != null)
{
int height;
if (int.TryParse(Style["height"].Replace("px", ""), out height))
size.Height = height;
writeHeight = false;
}
Color fColor = Color.Black;
if (GenerateStyle == GenerateStyle.Vista)
fColor = Color.White;
if (!ForeColor.IsEmpty)
fColor = ForeColor;
else if (Style["color"] != null)
{
ColorConverter conv = new ColorConverter();
fColor = (Color)conv.ConvertFrom(Style["color"]);
}
string altText = AlternateText;
string text = Text;
string imgPath = string.Empty;
if(Active)
{
if(!string.IsNullOrEmpty(ActiveImageUrl))
imgPath = Page.Server.MapPath(ActiveImageUrl);
if(string.IsNullOrEmpty(altText))
altText = ActiveText;
text = ActiveText;
}
else
{
if(!string.IsNullOrEmpty(ImageUrl))
imgPath = Page.Server.MapPath(ImageUrl);
if(string.IsNullOrEmpty(altText))
altText = Text;
}
Font textfont = Util.ConvertFont(Font);
if (this.IsEnabled)
{
GenerateImage normImg = new GenerateImage(GenerateStyle, GenerateImage.ButtonState.Normal, size, text, textfont, fColor, imgPath, CacheName,Page.Server.MapPath(CustomNormalImageUrl), Color.Empty);
writer.AddAttribute(HtmlTextWriterAttribute.Src, normImg.FullPath);
writer.AddAttribute("onmouseout", "this.src='" + normImg.FullPath + "';");
GenerateImage hovImg = new GenerateImage(GenerateStyle, GenerateImage.ButtonState.Hover, size, text, textfont, fColor, imgPath, CacheName, Page.Server.MapPath(CustomHoverImageUrl), Color.Empty);
writer.AddAttribute("onmouseover", "this.src='" + hovImg.FullPath + "';");
GenerateImage clickImg = new GenerateImage(GenerateStyle, GenerateImage.ButtonState.Clicked, size, text, textfont, fColor, imgPath, CacheName, Page.Server.MapPath(CustomClickedImageUrl), Color.Empty);
writer.AddAttribute("onmousedown", "this.src='" + clickImg.FullPath + "';");
if (!string.IsNullOrEmpty(OnClientClick))
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, OnClientClick);
size = normImg.Size;
}
else
{
GenerateImage disImg = new GenerateImage(GenerateStyle, GenerateImage.ButtonState.Disabled, size, text, textfont, fColor, imgPath, CacheName, Page.Server.MapPath(CustomDisabledImageUrl), CustomDisabledOverlayColor);
writer.AddAttribute(HtmlTextWriterAttribute.Src, disImg.FullPath);
size = disImg.Size;
//.........这里部分代码省略.........
示例13: Page_Load
// The Page_Load event handler on this User Control is used to
// obtain a DataReader of banner information from the Banners
// table, and then databind the results to a templated DataList
// server control. It uses the DotNetNuke.BannerDB()
// data component to encapsulate all data functionality.
protected void Page_Load( Object sender, EventArgs e )
{
try
{
int intPortalId=0;
int intBannerTypeId=0;
string strBannerGroup;
int intBanners = 0;
// banner parameters
switch( Convert.ToString( Settings["bannersource"] ) )
{
case "L": // local
intPortalId = PortalId;
break;
case "":
intPortalId = PortalId;
break;
case "G": // global
intPortalId = Null.NullInteger;
break;
}
if( Convert.ToString( Settings["bannertype"] ) != "" )
{
intBannerTypeId = int.Parse( Convert.ToString( Settings["bannertype"] ) );
}
strBannerGroup = Convert.ToString( Settings["bannergroup"] );
if( Convert.ToString( Settings["bannercount"] ) != "" )
{
intBanners = int.Parse( Convert.ToString( Settings["bannercount"] ) );
}
if( Convert.ToString( Settings["padding"] ) != "" )
{
lstBanners.CellPadding = int.Parse( Convert.ToString( Settings["padding"] ) );
}
// load banners
if( intBanners != 0 )
{
BannerController objBanners = new BannerController();
lstBanners.DataSource = objBanners.LoadBanners( intPortalId, ModuleId, intBannerTypeId, strBannerGroup, intBanners );
lstBanners.DataBind();
}
// set banner display characteristics
if( lstBanners.Items.Count != 0 )
{
// container attributes
lstBanners.RepeatLayout = RepeatLayout.Table;
if( Convert.ToString( Settings["orientation"] ) != "" )
{
switch( Convert.ToString( Settings["orientation"] ) )
{
case "H":
lstBanners.RepeatDirection = RepeatDirection.Horizontal;
break;
case "V":
lstBanners.RepeatDirection = RepeatDirection.Vertical;
break;
}
}
else
{
lstBanners.RepeatDirection = RepeatDirection.Vertical;
}
if( Convert.ToString( Settings["border"] ) != "" )
{
lstBanners.ItemStyle.BorderWidth = Unit.Parse( Convert.ToString( Settings["border"] ) + "px" );
}
if( Convert.ToString( Settings["bordercolor"] ) != "" )
{
ColorConverter objColorConverter = new ColorConverter();
lstBanners.ItemStyle.BorderColor = (Color)objColorConverter.ConvertFrom( Convert.ToString( Settings["bordercolor"] ) );
}
// item attributes
lstBanners.ItemStyle.VerticalAlign = VerticalAlign.Middle;
if( Convert.ToString( Settings["rowheight"] ) != "" )
{
lstBanners.ItemStyle.Height = Unit.Parse( Convert.ToString( Settings["rowheight"] ) + "px" );
}
if( Convert.ToString( Settings["colwidth"] ) != "" )
{
lstBanners.ItemStyle.Width = Unit.Parse( Convert.ToString( Settings["colwidth"] ) + "px" );
}
}
else
{
lstBanners.Visible = false;
}
//.........这里部分代码省略.........
示例14: CreateNode
//.........这里部分代码省略.........
try
{
imagePath = FunctionHelper.UpdateImageList(this.Controller, globalIL, paramValueForImage, true);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Image Load");
// use type
imagePath = nodeType;
}
LoadNode(nodeID, linkID, nodeName, nodeType, nodeFunctions, imagePath, xyFromDB, ref startX, ref startY, docNodes);
}
break;
case "Polygon": // parse [email protected] Points
// param name should have three parameters - poly points, color, alpha
if (actionValues.Count >= 3)
{
String polyPoints = parameterMap[actionValues[0]];
String polyColor = parameterMap[actionValues[1]];
String alpha = parameterMap[actionValues[2]];
DiagramPolygon polygon = new DiagramPolygon(this, nodeID, linkID, nodeName, nodeType, actionValues[0]);
polygon.Style = GoPolygonStyle.Line;
if (polyColor.Length > 0)
{
try
{
ColorConverter convertFromString = new ColorConverter();
Color convert = (Color)convertFromString.ConvertFrom(polyColor);
byte alphaByte = 255;
if (alpha.Length > 0)
{
alphaByte = Byte.Parse(alpha);
}
convert = Color.FromArgb(alphaByte, convert);
if (FillPolygon)
{
polygon.Brush = new SolidBrush(convert);
}
if (OutlinePolygon)
{
polygon.Pen = new Pen(convert, 2.0f);
}
}
catch (FormatException fex)
{
MessageBox.Show("Could not convert color", fex.Message);
}
}
polygon.Functions = nodeFunctions;
try
{
// this will throw an exception if an invalid string is used
List<PointF> polygonPoints = FunctionHelper.ParsePolygonString(polyPoints, nodeType, m_coordinateTransformer);
foreach (PointF polyPoint in polygonPoints)