Article | 60000296 |
Type | HowTo |
Product | Engine |
Version | 6 |
Date Added | 10/30/2007 |
Submitted by | ??? |
Keywords |
System.Collections.Generic.
Dictionary<int, System.Drawing.Color> dictionarycolor;public Form1()
{
InitializeComponent();
}
private void
Form1_Load(object
sender, EventArgs e)
{
vdFC.BaseControl.ActiveDocument.FreezeEntityDrawEvents.Push(false);
vdFC.BaseControl.ActiveDocument.OnDrawFigure += new
VectorDraw.Professional.vdObjects.vdDocument.FigureDrawEventHandler(ActiveDocument_OnDrawFigure);
//
this event is needed. The render of this event has the PenStyle.Color
}
private void
button3_Click(object
sender, EventArgs e)
{
//create
a dictionary to filter dublicate colors
dictionarycolor
= new Dictionary<int,
Color>();
countcolors = true;
vdFC.BaseControl.ActiveDocument.Open(vdFC.BaseControl.ActiveDocument.GetOpenFileNameDlg(0,
"", 0) as
string);
vdFC.BaseControl.ActiveDocument.Redraw(true);
countcolors = false;
//put
the colors from dictionary in a simple array of System colors.
System.Drawing.Color[]
usedcolors = new Color[dictionarycolor.Count];
int
i = 0;
foreach
(System.Collections.Generic.KeyValuePair<int,System.Drawing.Color>
var in
dictionarycolor)
{
usedcolors.SetValue(var.Value,i
); i++;
}
MessageBox.Show("different
colors used : "+ i.ToString());
}
void
ActiveDocument_OnDrawFigure(object
sender, VectorDraw.Render.vdRender
render, ref bool
cancel)
{
if
(countcolors)
{
int
key = render.PenStyle.color.GetHashCode();
if(dictionarycolor.ContainsKey(key))
return;
dictionarycolor.Add(key,
render.SystemPenColor); //add the color to
the dictionary if doesn't already exist
}
}