1. Use ComboBox to create a ribbon. First, draw
Private void comboboxincludrawitem (Object sender, drawitemeventargs E)
{
Rectangle rec = E. bounds;
Rec. width = Rec. width/array. length;
String fromcolor = combobox1.items [E. Index]. tostring (). Split ('|') [0];
String tocolor = combobox1.items [E. Index]. tostring (). Split ('|') [1];
_ Fromcolor = color. fromname (fromcolor );
_ Tocolor = color. fromname (tocolor );
Ialgorithmiccolorramp ramp = new algorithmiccolorrampclass (); // create a ribbon. You can also create a gradient ribbon using the lineargradientbrush class.
Ramp. fromcolor = colortoicolor (_ fromcolor );
Ramp. tocolor = colortoicolor (_ tocolor );
Ramp. size = array. length;
Bool OK = true;
Ramp. createramp (out OK );
Ienumcolors enumcolor = ramp. colors;
Icolor color = NULL;
Solidbrush sb = NULL;
For (INT I = 0; I <array. length; I ++)
{
Color = enumcolor. Next ();
SB = new solidbrush (icolortocolor (color ));
E. Graphics. fillrectangle (SB, REC );
Rec. offset (Rec. Width, 0); // offset the small rectangle.
}
}
2. Load
Combobox1.drawmode = drawmode. ownerdrawfixed; // make draw_item valid
Combobox1.dropdownstyle = comboboxstyle. dropdownlist;
Combobox1.items. Clear ();
Combobox1.beginupdate ();
Foreach (string onecolor in colorlist)
{
Combobox1.items. Add (onecolor );
}
Combobox1.endupdate ();
3. Define the color, the starting and ending colors of the ribbon
Private Static string [] colorlist = {"Black | White", "White | black", "Red | blue", "Green | black "};
4. rendering each value based on the obtained field value
First obtain the field value (not repeated)
Private double [] array;
Private void button#click (Object sender, eventargs E)
{
String layername = combobox2.selecteditem. tostring ();
String fieldname = combobox3.selecteditem. tostring ();
Selectlayer SL = new selectlayer (mapcontrol );
Ifeaturelayer layer = SL. getlayerbyname (layername) as ifeaturelayer;
Itablehistogram histogram = new basictablehistogramclass ();
Histogram. Field = fieldname;
Histogram. Table = layer as itable;
Ibasichistogram Basich = Histogram as ibasichistogram;
Object value = NULL;
Object frequece = NULL;
Basich. gethistogram (out value, out frequece );
Array = value as double [];
For (INT I = 0; I <array. length; I ++)
{
Listview1.items. Add (array [I]. tostring ());
}
}
Final rendering:
Private void button2_click (Object sender, eventargs E)
{
Selectlayer SL = new selectlayer (mapcontrol );
Igeofeaturelayer layer = SL. getlayerbyname (combobox2.selecteditem. tostring () as igeofeaturelayer;
String fieldname = combobox3.selecteditem. tostring ();
String item = combobox1.selecteditem. tostring ();
String begincolor = item. Split ('|') [0];
String finishcolor = item. Split ('|') [1];
Color _ begincolor = color. fromname (begincolor );
Color _ finishcolor = color. fromname (finishcolor );
Ialgorithmiccolorramp ramp = new algorithmiccolorrampclass ();
Ramp. fromcolor = colortoicolor (_ begincolor );
Ramp. tocolor = colortoicolor (_ finishcolor );
Ramp. size = array. length;
Bool OK = true;
Ramp. createramp (out OK );
Ienumcolors enumcolor = ramp. colors;
Icolor color = NULL;
Isimplefillsymbol fillsymbol = NULL;
Iuniquevaluerenderer valuerender = new uniquevaluerendererclass ();
Valuerender. fieldcount = 1;
Valuerender. set_field (0, fieldname );
For (INT I = 0; I <array. length; I ++)
{
Color = enumcolor. Next ();
Fillsymbol = new simplefillsymbolclass ();
Fillsymbol. Color = color;
Valuerender. addvalue (array [I]. tostring (), fieldname, fillsymbol as isymbol );
}
MessageBox. Show ("successful! ");
Layer. Renderer = valuerender as ifeaturerenderer;
Mapcontrol. Refresh ();
}
The final rendering result is shown in. The method may be clumsy, and the code is too repetitive, but the level is limited and the result is what you think, so I will share it with you giser.
In arcengine, create a ribbon