using System;
using System .Collections .Generic;
using System .Drawing;
using System .Windows .Forms;
using MoveGraphLibrary;
namespace Test_MoveGraphLibrary
{
public partial class Form_DefineNewBarChart : Form
{
int nSet, nSegment;
Color clrStart, clrEnd;
Rectangle rc;
BarChart chart;
Random rand;
int nSeed;
double [,] fVals; // = new double [nSet, nSegment];
string [] texts;
bool bAfterInit = false;
// -------------------------------------------------
public Form_DefineNewBarChart ()
{
InitializeComponent ();
//Font = new Font ("Times New Roman", 14);
}
// ------------------------------------------------- OnLoad
private void OnLoad (object sender, EventArgs e)
{
DateTime dt = DateTime .Now;
nSeed = dt .Hour * 3600 + dt .Minute * 60 + dt .Second;
while (nSeed < 10000)
{
nSeed += 1000;
}
rand = new Random (nSeed);
nSet = 3;
nSegment = 5;
numericSets .Value = nSet;
numericSegments .Value = nSegment;
comboTexts .SelectedIndex = 1;
int iStart = rand .Next (nSeed) % 7;
int iEnd = rand .Next (nSeed) % 7;
if (iStart == iEnd) iEnd++;
clrStart = Auxi_Colours .ColorPredefined (iStart);
clrEnd = Auxi_Colours .ColorPredefined (iEnd);
int cyT = numericSegments .Bottom + 12;
rc = new Rectangle (btnChange .Left, cyT, buttonOK .Right - btnChange .Left, buttonOK .Top - 12 - cyT);
SetBarChart ();
toolTip1 .SetToolTip (btnStartClr, Auxi_Convert .ClrToStr (clrStart, ColorStr .IN_ROWS));
toolTip1 .SetToolTip (btnEndClr, Auxi_Convert .ClrToStr (clrEnd, ColorStr .IN_ROWS));
bAfterInit = true;
}
// ================================================= SetBarChart
private void SetBarChart ()
{
fVals = new double [nSet, nSegment];
for (int i = 0; i < nSet; i++)
{
for (int j = 0; j < nSegment; j++)
{
fVals [i, j] = rand .Next (nSeed) % 1000;
}
}
if (bAfterInit)
{
texts = PrepareTexts ();
}
else
{
texts = Auxi_Common .strDays;
}
chart = new BarChart (this, rc, fVals, Side .S, texts, TextsDrawingDirection .LTtoRB, //Auxi_Common .strDays
Side .E, 1000.0, 0.0, GridOrigin .ByStep, 200.0);
chart .Colors = Auxi_Colours .SmoothColorsList (nSet, clrStart, clrEnd);
chart .FillCoefficients (0, 0.85);
chart .NumScale .Visible = false;
chart .TextScale .Visible = false;
}
// ------------------------------------------------- OnPaint
private void OnPaint (object sender, PaintEventArgs e)
{
chart .Draw (e .Graphics);
}
// ------------------------------------------------- ValueChanged_numericSets
private void ValueChanged_numericSets (object sender, EventArgs e)
{
if (bAfterInit)
{
nSet = Convert .ToInt32 (numericSets .Value);
SetBarChart ();
Invalidate ();
}
}
// ------------------------------------------------- ValueChanged_numericSegments
private void ValueChanged_numericSegments (object sender, EventArgs e)
{
if (bAfterInit)
{
nSegment = Convert .ToInt32 (numericSegments .Value);
SetBarChart ();
Invalidate ();
}
}
// ------------------------------------------------- Click_btnChange
private void Click_btnChange (object sender, EventArgs e)
{
SetBarChart ();
Invalidate ();
}
// ------------------------------------------------- Click_btnStartClr
private void Click_btnStartClr (object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog ();
dlg .Color = clrStart;
if (dlg .ShowDialog () == DialogResult .OK)
{
clrStart = dlg .Color;
chart .Colors = Auxi_Colours .SmoothColorsList (nSet, clrStart, clrEnd);
toolTip1 .SetToolTip (btnStartClr, Auxi_Convert .ClrToStr (clrStart, ColorStr .IN_ROWS));
Invalidate ();
}
}
// ------------------------------------------------- Click_btnEndClr
private void Click_btnEndClr (object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog ();
dlg .Color = clrEnd;
if (dlg .ShowDialog () == DialogResult .OK)
{
clrEnd = dlg .Color;
chart .Colors = Auxi_Colours .SmoothColorsList (nSet, clrStart, clrEnd);
toolTip1 .SetToolTip (btnStartClr, Auxi_Convert .ClrToStr (clrStart, ColorStr .IN_ROWS));
Invalidate ();
}
}
// ------------------------------------------------- BarChart
public BarChart BarChart
{
get { return (chart); }
}
// ------------------------------------------------- SelectedIndexChanged_comboTexts
private void SelectedIndexChanged_comboTexts (object sender, EventArgs e)
{
if (bAfterInit)
{
chart .TextScale .Texts = PrepareTexts ();
Invalidate ();
}
}
// ------------------------------------------------- PrepareTexts
private string [] PrepareTexts ()
{
string [] strs = new string [nSegment];
string [] strsSrc;
switch (comboTexts .SelectedIndex)
{
case 0:
default:
strsSrc = Auxi_Common .strAlphabet;
break;
case 1:
strsSrc = Auxi_Common .strDays;
break;
case 2:
strsSrc = Auxi_Common .strMonths;
break;
case 3:
strsSrc = Auxi_Common .strNames;
break;
}
for (int i = 0; i < nSegment; i++)
{
strs [i] = Auxi_Common .StringOfText (strsSrc, i);
}
return (strs);
}
}
}