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();
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 move three controls using this code on MouseMove Event :
if (inHareket)
{
GelenResimcik.Left = e.X + GelenResimcik.Left -MouseDownLocation.X;
GelenResimcik.Top = e.Y + GelenResimcik.Top - MouseDownLocation.Y;
GelenResimcik.BackColor = Color.Transparent;
ResimHareket.Left = e.X + ResimHareket.Left - MouseDownLocation.X;
ResimHareket.Top = e.Y + ResimHareket.Top - MouseDownLocation.Y;
Yonlendir.Left = e.X + Yonlendir.Left - MouseDownLocation.X;
Yonlendir.Top = e.Y + Yonlendir.Top - MouseDownLocation.Y;
Aktar.Left = e.X + Aktar.Left - MouseDownLocation.X;
Aktar.Top = e.Y + Aktar.Top - MouseDownLocation.Y;
Vazgec.Left = e.X + Vazgec.Left - MouseDownLocation.X;
Vazgec.Top = e.Y + Vazgec.Top - MouseDownLocation.Y;
}
and if I try move them faster the result is :
Notice : When i stop moving, the glow is not visible, it is only moving faster.
What shall I do?
EDIT :
My Controls
this.Yonlendir = new System.Windows.Forms.PictureBox();
this.Vazgec = new System.Windows.Forms.PictureBox();
this.Aktar = new System.Windows.Forms.PictureBox();
this.ResimHareket = new System.Windows.Forms.PictureBox();
this.GelenResimcik = new System.Windows.Forms.PictureBox();
My Init :
((System.ComponentModel.ISupportInitialize)(this.Yonlendir)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.Vazgec)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.Aktar)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ResimHareket)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.GelenResimcik)).BeginInit();
this.SuspendLayout();
//
// Yonlendir
//
this.Yonlendir.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40)))));
this.Yonlendir.Cursor = System.Windows.Forms.Cursors.Arrow;
this.Yonlendir.Image = global::Surface.Properties.Resources.rotate;
this.Yonlendir.Location = new System.Drawing.Point(26, 74);
this.Yonlendir.Name = "Yonlendir";
this.Yonlendir.Padding = new System.Windows.Forms.Padding(5);
this.Yonlendir.Size = new System.Drawing.Size(30, 30);
this.Yonlendir.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.Yonlendir.TabIndex = 14;
this.Yonlendir.TabStop = false;
this.Yonlendir.Click += new System.EventHandler(this.Yonlendir_Click);
//
// Vazgec
//
this.Vazgec.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40)))));
this.Vazgec.Cursor = System.Windows.Forms.Cursors.Arrow;
this.Vazgec.Image = global::Surface.Properties.Resources.iptal;
this.Vazgec.Location = new System.Drawing.Point(93, 8);
this.Vazgec.Name = "Vazgec";
this.Vazgec.Padding = new System.Windows.Forms.Padding(5);
this.Vazgec.Size = new System.Drawing.Size(30, 30);
this.Vazgec.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.Vazgec.TabIndex = 13;
this.Vazgec.TabStop = false;
this.Vazgec.Click += new System.EventHandler(this.buton1_Click);
//
// Aktar
//
this.Aktar.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40)))));
this.Aktar.Cursor = System.Windows.Forms.Cursors.Arrow;
this.Aktar.Image = global::Surface.Properties.Resources.kaydet;
this.Aktar.Location = new System.Drawing.Point(57, 8);
this.Aktar.Name = "Aktar";
this.Aktar.Padding = new System.Windows.Forms.Padding(5);
this.Aktar.Size = new System.Drawing.Size(30, 30);
this.Aktar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.Aktar.TabIndex = 12;
this.Aktar.TabStop = false;
this.Aktar.Click += new System.EventHandler(this.Onayla_Click);
//
// ResimHareket
//
this.ResimHareket.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40)))));
this.ResimHareket.Cursor = System.Windows.Forms.Cursors.Arrow;
this.ResimHareket.Image = global::Surface.Properties.Resources.hareket;
this.ResimHareket.Location = new System.Drawing.Point(26, 38);
this.ResimHareket.Name = "ResimHareket";
this.ResimHareket.Padding = new System.Windows.Forms.Padding(5);
this.ResimHareket.Size = new System.Drawing.Size(30, 30);
this.ResimHareket.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.ResimHareket.TabIndex = 11;
this.ResimHareket.TabStop = false;
this.ResimHareket.Click += new System.EventHandler(this.ResimHareket_Click);
this.ResimHareket.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ResmiHareket_MouseDown);
this.ResimHareket.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ResmiHareket_MouseMove);
this.ResimHareket.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ResimHareket_MouseUp);
//
// GelenResimcik
//
this.GelenResimcik.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.GelenResimcik.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.GelenResimcik.Location = new System.Drawing.Point(57, 39);
this.GelenResimcik.Name = "GelenResimcik";
this.GelenResimcik.Size = new System.Drawing.Size(438, 452);
this.GelenResimcik.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.GelenResimcik.TabIndex = 2;
this.GelenResimcik.TabStop = false;
My Timer (Interval 100):
private void ResimKontrol_Tick(object sender, EventArgs e)
{
try
{
if (ontanimli.Height != 0)
{
GelenResimcik.Image = ontanimliGelen;
GelenResimcik.Parent = cizim;
entegreGoster();
}
}
catch
{
}
}
entegreGoster and entegreGizle
public void entegreGoster() { GelenResimcik.BringToFront();ResimHareket.BringToFront();Aktar.BringToFront();Vazgec.BringToFront(); Yonlendir.BringToFront(); }
public void entegreGizle() { GelenResimcik.SendToBack(); ResimHareket.SendToBack(); Aktar.SendToBack(); Vazgec.SendToBack(); Yonlendir.SendToBack(); }
My MouseDown event :
private void ResmiHareket_MouseDown(object sender, MouseEventArgs e)
{
MouseDownLocation = e.Location;
inHareket = true;
}
I start timer when Open new form
Ontanimlilar ontanimli = new Ontanimlilar();
ontanimli.Show();
ResimKontrol.Start();
ontanimliGelen (public static pictureBox)
ontanimli Class :
Ciz.ontanimliGelen = seciliRes.Image;
this.Close();
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();
}
I want to have list of PictureBox inside the FlowLayoutPanel.These Picture box with images are added dynamically at run time. Now the problem I have got is, I have to add more than picturebox to panel and when I do that the picture box at the end seems to be missing though it seems like the space for those images are allocated.So how can I overcome this problem.
panel1.Controls.Clear();
Point NewLocation = new System.Drawing.Point(0, 0);
int CurrentImgIndex = 0;
foreach (ScannedImages image in Global.ScannedReportList[0].ImageCollection)
{
panel1.SuspendLayout();
PictureBox pbTemp = new PictureBox();
pbTemp.BackColor = System.Drawing.Color.Transparent;
pbTemp.Location = NewLocation;
pbTemp.Name = "picImage";
pbTemp.Size = new System.Drawing.Size(757*2, 980*2);
pbTemp.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
pbTemp.TabIndex = 7;
pbTemp.TabStop = false;
pbTemp.Tag = CurrentImgIndex + 1;
pbTemp.DragDrop += new System.Windows.Forms.DragEventHandler(this.PbTemp_DragDrop);
pbTemp.DragOver += new System.Windows.Forms.DragEventHandler(this.PbTemp_DragOver);
pbTemp.Click += new EventHandler(this.pbTemp_Click);
try
{
//pm
Image img = Global.ScannedReportList[0].ImageCollection[CurrentImgIndex].GetImageObject();
txtCurrentPage.Text = (CurrentImageIndex + 1).ToString();
//pm image
RotateAngle = Global.ScannedReportList[0].ImageCollection[CurrentImgIndex].RotationAngle;
//drpGroupTool.SelectedIndex = Global.ScannedReportList[0].ImageCollection[CurrentImgIndex].DocumentGroup;
switch (RotateAngle)
{
case 90:
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
case 180:
img.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case 270:
img.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
}
//pm
m_szOriginal = img.Size;
pbTemp.Image = img;
if (Brightness != 0)
pbTemp.Image = AdjustBrightness(new Bitmap(pbTemp.Image), Brightness);
if (Contrast != 0)
pbTemp.Image = AdjustContrast1(new Bitmap(pbTemp.Image), Contrast);
panel1.Controls.Add(pbTemp);
panel1.ResumeLayout();
this.panel1.PerformLayout();
this.panel1.Refresh();
//pm
if (RotateAngle == 90 || RotateAngle == 270)
{
NewLocation.Y += img.Width;
}
else if (RotateAngle == 0 || RotateAngle == 180)
{
NewLocation.Y += img.Height;
}
//
CurrentImgIndex++;
this.Refresh();
index[CurrentImgIndex] = CurrentImgIndex + 1;
}
catch
{
pbTemp.Image = null;
}
I'd like to modify this PictureBox Array Project.
i want to put a reset button than will clear all the PictureBox Array it created
more likely the form will be empty again as like from the beginning.
this is some of it's code;
// Function to add PictureBox Controls
private void AddControls(int cNumber)
{
imgArray = new System.Windows.Forms.PictureBox[cNumber]; // assign number array
for (int i = 0; i < cNumber; i++)
{
imgArray[i] = new System.Windows.Forms.PictureBox(); // Initialize one variable
}
// When call this function you determine number of controls
}
private void ImagesInFolder()
{
FileInfo FInfo;
// Fill the array (imgName) with all images in any folder
imgName = Directory.GetFiles(Application.StartupPath + #"\Images");
// How many Picture files in this folder
NumOfFiles = imgName.Length;
imgExtension = new string[NumOfFiles];
for (int i = 0; i < NumOfFiles; i++)
{
FInfo = new FileInfo(imgName[i]);
imgExtension[i] = FInfo.Extension; // We need to know the Extension
//
}
}
private void ShowFolderImages()
{
int Xpos = 8;
int Ypos = 8;
Image img;
Image.GetThumbnailImageAbort myCallback =
new Image.GetThumbnailImageAbort(ThumbnailCallback);
MyProgress.Visible = true;
MyProgress.Minimum = 1;
MyProgress.Maximum = NumOfFiles;
MyProgress.Value = 1;
MyProgress.Step = 1;
string[] Ext = new string [] {".GIF", ".JPG", ".BMP", ".PNG"};
AddControls(NumOfFiles);
for (int i = 0; i < NumOfFiles; i++)
{
switch (imgExtension[i].ToUpper())
{
case ".JPG":
case ".BMP":
case ".GIF":
case ".PNG":
img = Image.FromFile(imgName[i]); // or img = new Bitmap(imgName[i]);
imgArray[i].Image = img.GetThumbnailImage(64, 64, myCallback, IntPtr.Zero);
img = null;
if (Xpos > 432) // six images in a line
{
Xpos = 8; // leave eight pixels at Left
Ypos = Ypos + 72; // height of image + 8
}
imgArray[i].Left = Xpos;
imgArray[i].Top = Ypos;
imgArray[i].Width = 64;
imgArray[i].Height = 64;
imgArray[i].Visible = true;
// Fill the (Tag) with name and full path of image
imgArray[i].Tag = imgName[i];
imgArray[i].Click += new System.EventHandler(ClickImage);
this.BackPanel.Controls.Add(imgArray[i]);
Xpos = Xpos + 72; // width of image + 8
Application.DoEvents();
MyProgress.PerformStep();
break;
}
}
MyProgress.Visible = false;
}
private bool ThumbnailCallback()
{
return false;
}
private void btnLoad_Click(object sender, System.EventArgs e)
{
ImagesInFolder(); // Load images
ShowFolderImages(); // Show images on PictureBox array
this.Text = "Click wanted image";
}
how can i do that?
sorry i don't have any code for the reset button yet.
i don't know what to do, i am new to c#.
You can just set the image to null:
private void Clear()
{
foreach (var pictureBox in imgArray)
{
pictureBox.Image = null;
pictureBox.Invalidate();
}
}
I will follow this steps to be sure everything will be fred :
private void btnReset_Click(object sender, System.EventArgs e)
{
for(int x = this.BackPanel.Controls.Count - 1; x >= 0; x--)
{
if(this.BackPanel.Controls[x].GetType() == typeof(PictureBox))
this.BackPanel.Controls.Remove(x);
}
for(int x = 0; x < imgArray.Length; x++)
{
imgArray[x].Image = null;
imgArray[x] = null;
}
}
Assuming there are no other child controls in this.Backpanel (the container control that is actually displaying your images), this will probably work:
private void ClearImages() {
this.BackPanel.Controls.Clear();
imgArray = null;
}
Good Luck!
If you are drawing on a pictureBox and you want to clear it:
Graphics g = Graphics.FromImage(this.pictureBox1.Image);
g.Clear(this.pictureBox1.BackColor);
After that you can draw again on the control.
I hope this can help to someone.