I developed a Winform application which has a Panel as Main Screen and two other panels on each side for previous and next video. and Two buttons which helps the Application to traverse through different videos and set it to the main panel. I have 21 videos now......
This is My code....
public void loadvideo2(int a)
{
int width = viewscreen.Width;
int height = viewscreen.Height;
int width1 = nxtpnl.Width;
int height1 = nxtpnl.Height;
int width2 = prepnl.Width;
int height2 = prepnl.Height;
video = new Video(vpath[a]);
video.Owner = viewscreen;
video.Stop();
viewscreen.Size = new Size(width, height);
video1 = new Video(vpath[a + 1]);
video1.Owner = nxtpnl;
video1.Stop();
nxtpnl.Size = new Size(width1, height1);
video2 = new Video(vpath[a - 1]);
video2.Owner = prepnl;
video2.Stop();
prepnl.Size = new Size(width2, height2);
plystpBtn.BackgroundImage = Video_Project.Properties.Resources.Style_Play_icon__1_;
plystpBtn.BackgroundImageLayout = ImageLayout.Stretch;
trckstatus.Minimum = Convert.ToInt32(video.CurrentPosition);
trckstatus.Maximum = Convert.ToInt32(video.Duration);
duration = CalculateTime(video.Duration);
playposition = "0:00:00";
posdurtrclbl.Text = playposition + "/" + duration;
b = a;
vlbl.Text = "Video" + Convert.ToString(b);
}
private void preBtn_Click(object sender, EventArgs e)
{
videono += 1;
if (videono <= vcount-1)
{
loadvideo2(videono);
}
else
MessageBox.Show("File Not Found!!!");
}
private void nxtBtn_Click(object sender, EventArgs e)
{
videono -= 1;
if (videono >= 0)
{
loadvideo2(videono);
}
else
MessageBox.Show("FIle Not Found!!!");
}
now while i am traversing through the videos by pressing buttons its working fine till the 16th video where i am getting an error message
ffmpeg.dll failed to load
can any one help me to solve this
solved it. It was probably a memory consumption issue.
public void loadvideo2(int a)
{
int width = viewscreen.Width;
int height = viewscreen.Height;
int width1 = nxtpnl.Width;
int height1 = nxtpnl.Height;
int width2 = prepnl.Width;
int height2 = prepnl.Height;
video.Dispose();
video = new Video(vpath[a]);
video.Owner = viewscreen;
video.Stop();
viewscreen.Size = new Size(width, height);
video1 = new Video(vpath[a + 1]);
video1.Owner = nxtpnl;
video1.Stop();
nxtpnl.Size = new Size(width1, height1);
video2 = new Video(vpath[a - 1]);
video2.Owner = prepnl;
video2.Stop();
prepnl.Size = new Size(width2, height2);
plystpBtn.BackgroundImage = Video_Project.Properties.Resources.Style_Play_icon__1_;
plystpBtn.BackgroundImageLayout = ImageLayout.Stretch;
trckstatus.Minimum = Convert.ToInt32(video.CurrentPosition);
trckstatus.Maximum = Convert.ToInt32(video.Duration);
duration = CalculateTime(video.Duration);
playposition = "0:00:00";
posdurtrclbl.Text = playposition + "/" + duration;
b = a;
vlbl.Text = "Video" + Convert.ToString(b);
video1.Dispose();
video2.Dispose();
}
Related
I am trying to make a Windows Form that shows display data from data a table. Every thing is working fine until I start scrolling in the Form using the auto scroll property.
I don't know why that's happening. I hope someone can help me.
private void allShowsToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
// Load All the Shows from the database
DataTable dt = accesse.LoadAllShows();
// Create the allShows From
Form allShows = new Form();
// Create the Controls for the AllShows form.
PictureBox[] pic = new PictureBox[dt.Rows.Count];
Label[] showName = new Label[dt.Rows.Count], season = new Label[dt.Rows.Count], eps = new Label[dt.Rows.Count], typ = new Label[dt.Rows.Count];
TextBox[] txtShowName = new TextBox[dt.Rows.Count], txtSeason = new TextBox[dt.Rows.Count], txtEps = new TextBox[dt.Rows.Count], txtTyp = new TextBox[dt.Rows.Count];
// AllShows Form properties
allShows.BackColor = Color.White;
allShows.Font = new Font("Calibri", 14f, FontStyle.Regular);
allShows.ForeColor = Color.Black;
allShows.Size = new Size(1050, 700);
allShows.StartPosition = FormStartPosition.CenterScreen;
allShows.AutoScroll = true;
allShows.AutoScrollMargin = new Size(0, 18);
// Variables
int y = 325; // the distens bettwen the controls on the Y and X.
bool xTurn = false; // the axies turn.
int yTurnNum = 0; // the y turn number.
for (int i = 0; i < dt.Rows.Count; i++)
{
// PictureBox Poster Properties
pic[i] = new PictureBox();
pic[i].BorderStyle = BorderStyle.FixedSingle;
pic[i].Size = new Size(162, 288);
pic[i].SizeMode = PictureBoxSizeMode.StretchImage;
pic[i].Image = Image.FromFile(dt.Rows[i][4].ToString());
// Label showName Properties
showName[i] = new Label();
showName[i].Text = "Show Name: " + dt.Rows[i][0];
showName[i].AutoSize = true;
// Label Season Properties
season[i] = new Label();
season[i].Text = "Season: " + dt.Rows[i][1];
season[i].AutoSize = true;
// Label Eps Properties
eps[i] = new Label();
eps[i].Text = "Episodes: " + dt.Rows[i][2];
eps[i].AutoSize = true;
// Label Typ Properties
typ[i] = new Label();
typ[i].Text = "Typ: " + dt.Rows[i][3];
typ[i].AutoSize = true;
if (xTurn)
{
// Sitting the location of the controls on the X turn
pic[i].Location = new Point(515, pic[i - 1].Location.Y);
showName[i].Location = new Point(687, showName[i - 1].Location.Y);
season[i].Location = new Point(687, season[i - 1].Location.Y);
eps[i].Location = new Point(687, eps[i - 1].Location.Y);
typ[i].Location = new Point(687, typ[i - 1].Location.Y);
xTurn = false;
}
else
{
// Sitting the location of the controls on the Y turn
pic[i].Location = new Point(15, 15 + (yTurnNum * y));
showName[i].Location = new Point(187, 20 + (yTurnNum * y));
season[i].Location = new Point(187, 55 + (yTurnNum * y));
eps[i].Location = new Point(187, 90 + (yTurnNum * y));
typ[i].Location = new Point(187, 125 + (yTurnNum * y));
yTurnNum += 1;
xTurn = true;
}
allShows.Controls.Add(pic[i]);
allShows.Controls.Add(showName[i]);
allShows.Controls.Add(season[i]);
allShows.Controls.Add(eps[i]);
allShows.Controls.Add(typ[i]);
}
allShows.ShowDialog();
}
catch (Exception ex)
{
tools.ShowErrorMessageBox(ex.Message, "Error");
}
}
I hope this gif will help you to understand what is happening.
enter image description here
I am building a poker game where I need to show multiple poker hands at the same time. I can either show 1, 3, 5, or 10.
I have 1 main hand that will display all the time and I activate different views based on the amount of hands the player wants to play.
I have 2 main panels (main_hand_panel, and extra_hands_panel)
I add all the Panels in a List and when it's time, I call ShowHand on it.
I add the first poker hand to main_hand_panel like this:
Point startPosition = new Point(0, 0);
ComponentResourceManager resources = new ComponentResourceManager(typeof(MainScreen));
var mainPokerHand = new PokerPanel(startPosition, main_hand_panel.Size, offset, cardSize);
mainPokerHand.Initialize(resources);
this.main_hand_panel.Controls.Add(mainPokerHand);
allHands.Add(mainPokerHand);
Then depending on which screen I'm showing I draw and add the additional hands like this (five hands example shown)
public void DrawFivePlay(ComponentResourceManager resources)
{
Point startPosition = new Point(0, 0);
var containerSize = extra_hands_panel.Size;
containerSize.Height = Convert.ToInt32(containerSize.Height / 2);
containerSize.Width = Convert.ToInt32(containerSize.Width / 2);
for (int i = 0; i < 2; i++)
{
startPosition.Y = containerSize.Height * i;
var pokerHand = new PokerPanel(startPosition, containerSize, scale(offset, .30), scale(cardSize, .8));
pokerHand.Initialize(resources);
this.extra_hands_panel.Controls.Add(pokerHand);
allHands.Add(pokerHand);
}
startPosition.X = containerSize.Width;
startPosition.Y = 0;
for (int i = 0; i < 2; i++)
{
startPosition.Y = containerSize.Height * i;
var pokerHand = new PokerPanel(startPosition, containerSize, scale(offset, .30), scale(cardSize, .8));
pokerHand.Initialize(resources);
this.extra_hands_panel.Controls.Add(pokerHand);
allHands.Add(pokerHand);
}
}
When I'm ready to show the hands, I call reveal_click which goes through all the hands in List and displays them.
private void reveal_Click(object sender, EventArgs e)
{
foreach (var hand in allHands)
{
hand.ShowHand();
}
Application.DoEvents();
}
The interesting part is that it doesn't display the main hand, it will display all the others, but the only time it displays the first hand is when the program just started and we are playing only 1 hand. If I show any of the other play option, the first hand will not display anymore.
Here is the PokerPanel code:
namespace TEX_DrawPoker
{
public class PokerPanel : Panel
{
private PictureBox pictureBox1_5;
private PictureBox pictureBox1_1;
private PictureBox pictureBox1_2;
private PictureBox pictureBox1_3;
private PictureBox pictureBox1_4;
Timer drawTimer = new Timer();
int timerTick = 0;
string[] pokerHand;
Size panelSize = new Size(5*229, 275);
Size cardSize = new Size(146, 202);
Point startPosition = new Point(0, 3);
Point firstCardPosition = new Point(0, 0);
Point offset = new Point(160, 0);
public PokerPanel(Point _startPosition,Size _panelSize, Point _offset, Size _cardSize)
{
drawTimer.Tick += new EventHandler(startDisplay);
drawTimer.Interval = 100;
drawTimer.Enabled = false;
panelSize = _panelSize;
cardSize = _cardSize;
offset = _offset;
startPosition = _startPosition;
}
public void startDisplay(object sender, EventArgs e)
{
switch (timerTick)
{
case 0:
this.pictureBox1_1.Image = (Image)(new Bitmap(Image.FromFile(".\\img\\cards\\" + pokerHand[timerTick] + ".png"), cardSize));
break;
case 1:
this.pictureBox1_2.Image = (Image)(new Bitmap(Image.FromFile(".\\img\\cards\\" + pokerHand[timerTick] + ".png"), cardSize));
break;
case 2:
this.pictureBox1_3.Image = (Image)(new Bitmap(Image.FromFile(".\\img\\cards\\" + pokerHand[timerTick] + ".png"), cardSize));
break;
case 3:
this.pictureBox1_4.Image = (Image)(new Bitmap(Image.FromFile(".\\img\\cards\\" + pokerHand[timerTick] + ".png"), cardSize));
break;
case 4:
this.pictureBox1_5.Image = (Image)(new Bitmap(Image.FromFile(".\\img\\cards\\" + pokerHand[timerTick] + ".png"), cardSize));
break;
}
if (timerTick >= 4)
{
drawTimer.Stop();
timerTick = 0;
}
else
{
timerTick++;
}
}
public void ShowHand()
{
pokerHand = Deck.shuffle();
drawTimer.Start();
}
public void Reset()
{
Image back = Image.FromFile(".\\img\\cards\\back.png");
this.pictureBox1_1.Image = (Image)(new Bitmap(back, cardSize));
this.pictureBox1_2.Image = (Image)(new Bitmap(back, cardSize));
this.pictureBox1_3.Image = (Image)(new Bitmap(back, cardSize));
this.pictureBox1_4.Image = (Image)(new Bitmap(back, cardSize));
this.pictureBox1_5.Image = (Image)(new Bitmap(back, cardSize));
}
public void Initialize(ComponentResourceManager resources)
{
Image back = Image.FromFile(".\\img\\cards\\back.png");
this.pictureBox1_1 = new System.Windows.Forms.PictureBox();
this.pictureBox1_2 = new System.Windows.Forms.PictureBox();
this.pictureBox1_3 = new System.Windows.Forms.PictureBox();
this.pictureBox1_4 = new System.Windows.Forms.PictureBox();
this.pictureBox1_5 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1_1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1_2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1_3)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1_4)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1_5)).BeginInit();
this.SuspendLayout();
//
// hand_1
//
this.Controls.Add(this.pictureBox1_5);
this.Controls.Add(this.pictureBox1_4);
this.Controls.Add(this.pictureBox1_3);
this.Controls.Add(this.pictureBox1_2);
this.Controls.Add(this.pictureBox1_1);
this.Location = startPosition;
this.Name = "hand_1";
this.Size = panelSize;
this.TabIndex = 0;
//
// pictureBox1_1
//
this.pictureBox1_1.Image = (Image)(new Bitmap(back, cardSize));
this.pictureBox1_1.Location = firstCardPosition;
this.pictureBox1_1.Name = "pictureBox1_1";
this.pictureBox1_1.Size = cardSize;
this.pictureBox1_1.TabIndex = 4;
this.pictureBox1_1.TabStop = false;
//
// pictureBox1_2
//
var positionCard_2 = firstCardPosition;
positionCard_2.Offset(offset);
this.pictureBox1_2.Image = (Image)(new Bitmap(back, cardSize));
this.pictureBox1_2.Location = positionCard_2;
this.pictureBox1_2.Name = "pictureBox1_2";
this.pictureBox1_2.Size = cardSize;
this.pictureBox1_2.TabIndex = 3;
this.pictureBox1_2.TabStop = false;
//
// pictureBox1_3
//
var positionCard_3 = positionCard_2;
positionCard_3.Offset(offset);
this.pictureBox1_3.Image = (Image)(new Bitmap(back, cardSize));
this.pictureBox1_3.Location = positionCard_3;
this.pictureBox1_3.Name = "pictureBox1_3";
this.pictureBox1_3.Size = cardSize;
this.pictureBox1_3.TabIndex = 2;
this.pictureBox1_3.TabStop = false;
//
// pictureBox1_4
//
var positionCard_4 = positionCard_3;
positionCard_4.Offset(offset);
this.pictureBox1_4.Image = (Image)(new Bitmap(back, cardSize));
this.pictureBox1_4.Location = positionCard_4;
this.pictureBox1_4.Name = "pictureBox1_4";
this.pictureBox1_4.Size = cardSize;
this.pictureBox1_4.TabIndex = 1;
this.pictureBox1_4.TabStop = false;
//
// pictureBox1_5
//
var positionCard_5 = positionCard_4;
positionCard_5.Offset(offset);
this.pictureBox1_5.Image = (Image)(new Bitmap(back, cardSize));
this.pictureBox1_5.Location = positionCard_5;
this.pictureBox1_5.Name = "pictureBox1_5";
this.pictureBox1_5.Size = cardSize;
this.pictureBox1_5.TabIndex = 0;
this.pictureBox1_5.TabStop = false;
((System.ComponentModel.ISupportInitialize)(this.pictureBox1_5)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1_4)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1_3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1_2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1_1)).EndInit();
}
}
}
I also use a timer to display the cards so that they stagger.
Any help would be appreciated.
Thanks,
Found my problem,
I was not clearing the controls between hand changes, so I was trying to update a panel that was in the background. Controls.Clear() before moving to the next hand fixed that for me. Sorry for the long post for nothing. :(
Have you considered refreshing the entire form?
Form1.Refresh();
or only refresh the panel
PokerPanel.Refresh();
I would like to create a new dynamic chart control.
This chart will have a lot of code behind it that works out data calculations and then populates properties of the chart.
My form class is getting rather large and I'm now thinking of putting all this new code im going to create in a new class (possibly call it "DynmChart").
Normally to use controls I would create a new class and then instantiate the form in the new class.
But my form class is part of a winforms project that uses program.c as its main class.
main contains application.run Form1.
So how would I create all the code etc that calculates and then populates controls that are in my form.
Here's all my code.
2 classes
Form1
Program
namespace RepSalesNetAnalysis
{
public partial class Form1 : Form
{
float top = 0;
float tmid = 0;
float bmid = 0;
float bottom = 0;
float tempTop = 0;
float tempMidt = 0;
float tempMidB = 0;
float tempBot = 0;
string meh;
DataTable pgTable = new DataTable();
public Form1()
{
InitializeComponent();
pictureBox2.Visible = false;
}
//button to run SalesFigures
private void button1_Click_1(object sender, EventArgs e)
{
checkBox1.Checked = true;
string acct = accCollection.Text;
Task t = new Task(() => GetsalesFigures(acct));
t.Start();
}
//invoke method for setting the picture box visible(grabs the control out of the form to use in a thread)
private void SetPictureBoxVisibility(bool IsVisible)
{
if (pictureBox2.InvokeRequired)
{
pictureBox2.Invoke(new Action<bool>(SetPictureBoxVisibility), new Object[] { IsVisible });
}
else
{
pictureBox2.Visible = IsVisible;
}
}
//invoke method for a check box toggle(to be used for testing
private void SetCheckBoxValue(bool IsChecked)
{
if (checkBox1.InvokeRequired)
{
pictureBox2.Invoke(new Action<bool>(SetCheckBoxValue), new Object[] { IsChecked });
}
else
{
checkBox1.Checked = IsChecked;
}
}
//invoke method to add customers and pass it to the sales method
private void AddItem(string value)
{
if (accCollection.InvokeRequired)
{
accCollection.Invoke(new Action<string>(AddItem), new Object[] { value });
}
else
{
accCollection.Items.Add(value);
}
}
//invoke method to set the datagrid properties
private void SetDataGrid(bool AutoGenerateColumns, Object DataSource, String DataMember, DataGridViewAutoSizeColumnsMode Mode)
{
if (this.dataGridView1.InvokeRequired)
{
this.dataGridView1.Invoke(new Action<bool, Object, String, DataGridViewAutoSizeColumnsMode>(SetDataGrid),
AutoGenerateColumns, DataSource, DataMember, Mode);
}
else
{
this.dataGridView1.AutoGenerateColumns = AutoGenerateColumns;
this.dataGridView1.DataSource = DataSource;
this.dataGridView1.DataMember = DataMember;
dataGridView1.AutoResizeColumns(Mode);
}
}
//on form load run the accounts too combco box method
private void Form1_Load(object sender, EventArgs e)
{
AutofillAccounts();
}
//method for task to get sales info
private void GetsalesFigures(string Acct)
{
try
{
string myConn = "Server=sgsg;" +
"Database=shaftdata;" +
"uid=bsgsg;" +
"pwd=drsgsg;" +
"Connect Timeout=120;";
string acct;// test using 1560
SqlConnection conn = new SqlConnection(myConn);
SqlCommand Pareto = new SqlCommand();
BindingSource bindme = new BindingSource();
SqlDataAdapter adapt1 = new SqlDataAdapter(Pareto);
DataSet dataSet1 = new DataSet();
DataTable table1 = new DataTable();
acct = Acct;
string fromDate = this.dateTimePicker1.Value.ToString("MM/dd/yyyy");
string tooDate = this.dateTimePicker2.Value.ToString("MM/dd/yyyy");
Pareto.Connection = conn;
Pareto.CommandType = CommandType.StoredProcedure;
Pareto.CommandText = "dbo.GetSalesParetotemp";
Pareto.CommandTimeout = 120;
Pareto.Parameters.AddWithValue("#acct", acct);
Pareto.Parameters.AddWithValue("#from", fromDate);
Pareto.Parameters.AddWithValue("#too", tooDate);
SetCheckBoxValue(true);
SetPictureBoxVisibility(true);
adapt1.Fill(dataSet1, "Pareto");
SetCheckBoxValue(false);
SetPictureBoxVisibility(false);
SetDataGrid(true, dataSet1, "Pareto", DataGridViewAutoSizeColumnsMode.AllCells);
dataGridView1.AutoResizeColumns(
DataGridViewAutoSizeColumnsMode.AllCells);
}
catch (Exception execc)
{
MessageBox.Show("Whoops! Seems we couldnt connect to the server!"
+ " information:\n\n" + execc.Message + execc.StackTrace,
"Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
//method non-task to get customer info
private void AutofillAccounts()
{
try
{
string myConn1 = "Server=sgsdg;" +
"Database=AutoPart;" +
"uid=bsgdg;" +
"pwd=dsgsg;" +
"Connect Timeout=6000;";
SqlConnection conn1 = new SqlConnection(myConn1);
conn1.Open();
SqlCommand accountFill = new SqlCommand("SELECT keycode FROM dbo.Customer", conn1);
SqlCommand pgFill = new SqlCommand("SELECT DISTINCT pg FROM dbo.Product", conn1);
SqlDataReader readacc = accountFill.ExecuteReader();
while (readacc.Read())
{
AddItem(readacc.GetString(0).ToString());
}
conn1.Close();
////////////////////////////////////////
conn1.Open();
SqlDataReader readpg = pgFill.ExecuteReader();
while (readpg.Read())
{
cmbPrdGrp.Items.Add(readpg.GetString(0).ToString());
}
conn1.Close();
}
catch(Exception exc1)
{
MessageBox.Show("Whoops! Seems we couldnt connect to the server!"
+ " information:\n\n" + exc1.Message + exc1.StackTrace,
"Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
//spare method for testing
private void spare()
{
chartControl1.Series.Clear();
chartControl2.Series.Clear();
meh = cmbPrdGrp.Text;
bottom = 0;
bmid = 0;
tmid = 0;
top = 0;
double countTot = 0;
double countPg = 0;
double percent = 0;
//ok lets set the properties on click
//get pareto data from datagrid using count
foreach (DataGridViewRow row in dataGridView1.Rows)
{
//count total
countTot++;
if ((string)row.Cells["Pg"].Value == meh)
{
//need to some how count pgs hmmmm
//countpg
countPg++;
if ((int)row.Cells["Pareto"].Value <= 50)
{
//top 50
//top++;
tempTop = Convert.ToSingle(row.Cells["Qty"].Value);
top += tempTop;
}
else
if (((int)row.Cells["Pareto"].Value > 50) && ((int)row.Cells["Pareto"].Value <= 100))
{
//50-100
tempMidt = Convert.ToSingle(row.Cells["Qty"].Value);
tmid += tempMidt;
}
else
if (((int)row.Cells["Pareto"].Value > 100) && ((int)row.Cells["Pareto"].Value <= 200))
{
//100-200
tempMidB = Convert.ToSingle(row.Cells["Qty"].Value);
bmid += tempMidB;
}
else
{
//its over 200!!!!!!!!!!!!!!
tempBot = Convert.ToSingle(row.Cells["Qty"].Value);
bottom += tempBot;
}
}
}
textBox1.Text = top.ToString();
textBox2.Text = tmid.ToString();
textBox3.Text = bmid.ToString();
textBox4.Text = bottom.ToString();
//calc percent
percent = (countPg / countTot);
//String.Format("{%#0:00}", percent);
//display counts as percentage of total
textBox5.Text = countTot.ToString();
textBox6.Text = percent.ToString("p1");
double[] yValues = { bottom, bmid, tmid, top };
string[] xNames = { "Greater than 200", "Between 200-100", "Between 100-50", "Below 50" };
//chart1.Series[0].Points.DataBindXY(xNames, yValues);
DataTable chartTable = new DataTable("Table1");
// Add two columns to the table.
chartTable.Columns.Add("Names", typeof(string));
chartTable.Columns.Add("Value", typeof(Int32));
chartTable.Rows.Add("Below 50", top);
chartTable.Rows.Add("Between 50-100", tmid);
chartTable.Rows.Add("Between 100-200", bmid);
chartTable.Rows.Add("Greater than 200", bottom);
Series series1 = new Series("Series1", ViewType.Pie3D);
Series series2 = new Series("Series2", ViewType.Bar);
chartControl2.Series.Add(series1);
chartControl1.Series.Add(series2);
series1.DataSource = chartTable;
series2.DataSource = chartTable;
series1.ArgumentScaleType = ScaleType.Qualitative;
series2.ArgumentScaleType = ScaleType.Qualitative;
series1.ArgumentDataMember = "names";
series2.ArgumentDataMember = "names";
series1.ValueScaleType = ScaleType.Numerical;
series2.ValueScaleType = ScaleType.Numerical;
series1.ValueDataMembers.AddRange(new string[] { "Value" });
series2.ValueDataMembers.AddRange(new string[] { "Value" });
//series1.Label.PointOptions.PointView = PointView.ArgumentAndValues;
series1.LegendPointOptions.PointView = PointView.ArgumentAndValues;
series2.LegendPointOptions.PointView = PointView.ArgumentAndValues;
series1.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
series2.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
series1.LegendPointOptions.ValueNumericOptions.Precision = 0;
series2.LegendPointOptions.ValueNumericOptions.Precision = 0;
// Adjust the value numeric options of the series.
series1.Label.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
//series2.Label.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
series1.Label.PointOptions.ValueNumericOptions.Precision = 0;
//series2.Label.PointOptions.ValueNumericOptions.Precision = 0;
// Adjust the view-type-specific options of the series.
((Pie3DSeriesView)series1.View).Depth = 20;
((Pie3DSeriesView)series1.View).ExplodedPoints.Add(series1.Points[0]);
((Pie3DSeriesView)series1.View).ExplodedPoints.Add(series1.Points[1]);
((Pie3DSeriesView)series1.View).ExplodedPoints.Add(series1.Points[2]);
((Pie3DSeriesView)series1.View).ExplodedPoints.Add(series1.Points[3]);
((Pie3DSeriesView)series1.View).ExplodedDistancePercentage = 20;
//((BarSeriesView)series2.View).
chartControl2.Legend.Visible = true;
chartControl1.Legend.Visible = true;
//series1.Label.PointOptions.ValueNumericOptions.Format = NumericFormat.Currency;
}
//spare button for testing
private void tempButton_Click(object sender, EventArgs e)
{
spare();
SpendsAnalysis();
}
private void Close_Click(object sender, EventArgs e)
{
Close();
}
private void Piebutton_Click(object sender, EventArgs e)
{
/*Rectangle tabArea;
RectangleF tabTextArea;
Bitmap B = new Bitmap(250, 250, PixelFormat.Format32bppArgb);
tabArea = new Rectangle(1, 1, 240, 240);
tabTextArea = new RectangleF(1, 1, 240, 240);
using (Graphics g = Graphics.FromImage(B))
{
int i1 = bottom;
int i2 = bmid;
int i3 = tmid;
int i4 = top;
float total = i1 + i2 + i3 + i4;
float deg1 = (i1 / total) * 360;
float deg2 = (i2 / total) * 360;
float deg3 = (i3 / total) * 360;
float deg4 = (i4 / total) * 360;
Font font = new Font("Arial", 10.0f);
SolidBrush brush = new SolidBrush(Color.Red);
Pen p = new Pen(Color.Empty, 0);
Brush b1 = new SolidBrush(Color.DarkRed);
Brush b2 = new SolidBrush(Color.DarkOrange);
Brush b3 = new SolidBrush(Color.DarkGray);
Brush b4 = new SolidBrush(Color.DarkViolet);
//g.DrawRectangle(p, tabArea);
g.DrawPie(p, tabTextArea, 0, deg1);
g.FillPie(b1, tabArea, 0, deg1);
g.DrawPie(p, tabTextArea, deg1, deg2);
g.FillPie(b2, tabArea, deg1, deg2);
g.DrawPie(p, tabTextArea, deg2 + deg1, deg3);
g.FillPie(b3, tabArea, deg2 + deg1, deg3);
g.DrawPie(p, tabTextArea, deg3 + deg2 + deg1, deg4);
g.FillPie(b4, tabArea, deg3 + deg2 + deg1, deg4);
//set picturebox3 as data source??
pictureBox3.Image = B;
textBox1.Text = top.ToString();
textBox2.Text = tmid.ToString();
textBox3.Text = bmid.ToString();
textBox4.Text = bottom.ToString();
//chart1.DataBind(x);
}*/
}
//need to create a more dynamic chart that will give details via PG.
//iether by internal filtering OR via queries(queries take time)
private void ChartByPrdGrp()
{
//sort data from frid via grp
foreach (DataGridViewRow pgrow in dataGridView1.Rows)
{
if ((string)pgrow.Cells["Pg"].Value == meh)
{
//add this row to new table called boots
pgTable.Rows.Add(dataGridView1.Rows);//this?
pgTable.Rows.Add(pgrow);//or this?
}
}
}
private void SpendsAnalysis()
{
float tempQtypg = 0;
float tempPricepg = 0;
double tempTotpg = 0;
double totalpg = 0;
float tempQty = 0;
float tempPrice = 0;
float tempTot = 0;
float total = 0;
float qtyPg = 0;
float qty = 0;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
tempQty = Convert.ToSingle(row.Cells["Qty"].Value);
tempPrice = Convert.ToSingle(row.Cells["Unit"].Value);
tempTot = tempQty * tempPrice;
total += tempTot;
qty += tempQty;
if ((string)row.Cells["Pg"].Value == meh)
{
//tempQty = (float)row.Cells["Qty"].Value;
tempQtypg = Convert.ToSingle(row.Cells["Qty"].Value);
tempPricepg = Convert.ToSingle(row.Cells["Unit"].Value);
tempTotpg = tempQtypg * tempPricepg;
totalpg += tempTotpg;
qtyPg += tempQtypg;
}
}
textBox12.Text = total.ToString("c");
textBox7.Text = totalpg.ToString("c");
textBox13.Text = qty.ToString();
textBox8.Text = qtyPg.ToString();
}
}
}
program class is my MAIN class:
namespace RepSalesNetAnalysis
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
any help would be great!
Many Thanks in Advance!
If I'm understanding your question right...
DynmChart should probably be created as a UserControl and used on forms where it's needed.
However, if you stay with your current approach:
You can use Encapsulation to separate responsibilities between the Form1 class (or your UserControl if you go that route) and a new Calculation class. The UI class would be responsible for display tasks, while the Calculation class would be responsible for number crunching. Simply create an instance of Calculation in Form1/your UserControl and use the Calculation instance to return results of the various calculations you need.
If the UI portion of your control is becoming unmanageable in terms of the amount of code in one file, the first thing to consider is using #region directives to hide parts of the code you are not working on (organize the code into blocks that logically belong together).
Another approach, if you need a lot of UI code and it's bloating your class file, is to use Partial Classes.
I want to create a custom messagebox
but i want use the custom icons and custom sound in during show messagebox
how do I create this Messagebox??
I no want to use the shell32.dll and user32.dll
a messagebox the same as windows 7 for windows xp
I used a simple dialog with a static method ShowCustomButtonsDialog. I placed a text label in the top left corner and changed border style to Dialog. Method simply returns button index or -1.
public partial class CustomButtonsDialog : Form
{
private const int ButtonHeight = 24;
private const int ButtonPadding = 6;
private const int ButtonInnerPadding = 5;
private const int MaxFormWidth = 700;
private int buttonIndex = -1;
public int ButtonIndex
{
get { return buttonIndex; }
private set { buttonIndex = value; }
}
public static int ShowCustomButtonsDialog(string text, string title, params string[] buttonsText)
{
var dlg = new CustomButtonsDialog(text, title, buttonsText.ToList());
dlg.ShowDialog();
return dlg.ButtonIndex;
}
public static int ShowCustomButtonsDialog(string text, string title, List<string> buttonsText)
{
var dlg = new CustomButtonsDialog(text, title, buttonsText);
dlg.ShowDialog();
return dlg.ButtonIndex;
}
public CustomButtonsDialog()
{
InitializeComponent();
}
private CustomButtonsDialog(string text, string title, List<string> buttonsText)
{
InitializeComponent();
Text = title;
labelText.Text = text;
// добавить кнопки
var formWidth = ClientSize.Width;
List<int> buttonWidths;
using (var gr = CreateGraphics())
{
buttonWidths = buttonsText.Select(b => (int)gr.MeasureString(b, Font).Width + 2 * ButtonInnerPadding).ToList();
}
var totalButtonWd = buttonWidths.Sum() + (buttonWidths.Count - 1) * ButtonPadding;
if (totalButtonWd > formWidth)
{
if (totalButtonWd <= MaxFormWidth)
Width = Width - ClientSize.Width + totalButtonWd + ButtonPadding * 2;
else
{// trim some buttons
Width = Width - ClientSize.Width + MaxFormWidth;
totalButtonWd = ClientSize.Width - ButtonPadding * 2;
var avgWidth = (totalButtonWd - (buttonsText.Count - 1) * ButtonPadding) / buttonsText.Count;
var sumThins = buttonWidths.Sum(w => w <= avgWidth ? w : 0);
var countThins = buttonWidths.Count(w => w <= avgWidth);
var countFat = buttonsText.Count - countThins;
var spareRoom = totalButtonWd - sumThins;
var fatWidth = (countThins == 0) || (countFat == 0)
? avgWidth
: (spareRoom - (countThins - 1)*ButtonPadding)/countFat;
for (var i = 0; i < buttonWidths.Count; i++)
if (buttonWidths[i] > avgWidth) buttonWidths[i] = fatWidth;
}
}
// buttons' Y-coords and height
labelText.MaximumSize = new Size(totalButtonWd,
labelText.MaximumSize.Height);
var buttonTop = labelText.Bottom + ButtonPadding;
var formHeight = buttonTop + ButtonHeight + ButtonPadding;
Height = Height - ClientSize.Height + formHeight;
// do make buttons
var buttonLeft = ButtonPadding;
var tag = 0;
for (var i = 0; i < buttonWidths.Count; i++)
{
var button = new Button
{
Parent = this,
Width = buttonWidths[i],
Height = ButtonHeight,
Left = buttonLeft,
Top = buttonTop,
Text = buttonsText[i],
Tag = tag++
};
button.Click += ButtonClick;
buttonLeft = button.Right + ButtonPadding;
Controls.Add(button);
}
}
private void ButtonClick(object sender, EventArgs e)
{
ButtonIndex = (int) ((Button) sender).Tag;
Close();
}
}
Easiest way would be to create your own MessageBox window from scratch. If you are looking for hooks to default windows MessageBox you need to consider that later you can run into problems like compatibility with other Windows operating systems.
Here are couple of samples how to create your own MessageBox:
Creating A Custom Message Box
A Custom Message Box
Custom Message Box
That will give you an idea about logic and how to start writing your own custom MessageBox.
my panel in my windows form application doesn't include all the buttons i asked it to. It shows only 1 button, Here is the code
private void AddAlphaButtons()
{
char alphaStart = Char.Parse("A");
char alphaEnd = Char.Parse("Z");
for (char i = alphaStart; i <= alphaEnd; i++)
{
string anchorLetter = i.ToString();
Button Buttonx = new Button();
Buttonx.Name = "button " + anchorLetter;
Buttonx.Text = anchorLetter;
Buttonx.BackColor = Color.DarkSlateBlue;
Buttonx.ForeColor = Color.GreenYellow;
Buttonx.Width = 30;
Buttonx.Height = 30;
this.panelButtons.Controls.Add(Buttonx);
//Buttonx.Click += new System.EventHandler(this.MyButton_Click);
}
}
Aren't they all going to be on the same position?
Try setting Buttonx.Location = new Point(100, 200);
(but with different points for different buttons)
You could use a FlowLayoutPanel, which would take care of the layout for you, or you need to track the locations yourself, or which could look something like this:
private void AddAlphaButtons()
{
char alphaStart = Char.Parse("A");
char alphaEnd = Char.Parse("Z");
int x = 0; // used for location info
int y = 0; // used for location info
for (char i = alphaStart; i <= alphaEnd; i++)
{
string anchorLetter = i.ToString();
Button Buttonx = new Button();
Buttonx.Name = "button " + anchorLetter;
Buttonx.Text = anchorLetter;
Buttonx.BackColor = Color.DarkSlateBlue;
Buttonx.ForeColor = Color.GreenYellow;
Buttonx.Width = 30;
Buttonx.Height = 30;
// set button location
Buttonx.Location = new Point(x, y);
x+=30;
if(x > panel1.Width - 30)
{
x = 30;
y+=30;
}
this.panelButtons.Controls.Add(Buttonx);
//Buttonx.Click += new System.EventHandler(this.MyButton_Click);
}
}