Click here to Skip to main content
15,897,891 members
Home / Discussions / C#
   

C#

 
AnswerRe: Best way to make Telephone Directory program Pin
Luc Pattyn21-Feb-11 15:14
sitebuilderLuc Pattyn21-Feb-11 15:14 
GeneralRe: Best way to make Telephone Directory program Pin
shivamkalra21-Feb-11 15:28
shivamkalra21-Feb-11 15:28 
AnswerRe: Best way to make Telephone Directory program Pin
Luc Pattyn21-Feb-11 15:33
sitebuilderLuc Pattyn21-Feb-11 15:33 
GeneralRe: Best way to make Telephone Directory program Pin
shivamkalra21-Feb-11 15:40
shivamkalra21-Feb-11 15:40 
GeneralRe: Best way to make Telephone Directory program Pin
Luc Pattyn21-Feb-11 15:50
sitebuilderLuc Pattyn21-Feb-11 15:50 
AnswerRe: Best way to make Telephone Directory program Pin
PIEBALDconsult21-Feb-11 15:38
mvePIEBALDconsult21-Feb-11 15:38 
GeneralRe: Best way to make Telephone Directory program Pin
shivamkalra21-Feb-11 15:47
shivamkalra21-Feb-11 15:47 
Questiondraw problem Pin
om_metab21-Feb-11 12:24
om_metab21-Feb-11 12:24 
I have problem with this code is draw ships many time
if u have any idea about it

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;

using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;

namespace DrawingGeomerticShips
{
public partial class Form1 : System.Windows.Forms.Form
{
private Pen nPen;
public Form1():base()
{
InitializeComponent();

nPen = new Pen(Color.Black);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
//private Bitmap ColorMap;
public enum dModes : int
{
Line,
Rectangle,
Ellipse,
Brush,
Path,
Text,
Eraser
}
//private Bitmap bmp;
private Bitmap bmp2;
private Graphics g2;
private Color clr= Color.Red;
//private Color clr2 = Color.blue;
private int StartX;
private int StartY;
private int EndX;
private int EndY;
private int BoxWidth;
private int BoxHeight;
private System.Drawing.Drawing2D.GraphicsPath mpath = new System.Drawing.Drawing2D.GraphicsPath();
private dModes dmode;
private int xLoc;
private int yLoc;
//private dStyles dstyle = dStyles.Outline;
private Int16 pWidth = 1;
//private Cursor c = new Cursor(GetEmbeddedFile("Whiteboard.ColorPicker.ico"));
//private Cursor er = new Cursor(GetEmbeddedFile("Whiteboard.Eraser.ico"));
private bool isDraw;
private PointF pF;
private PointF pFOld;

[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint="HideCaret", ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
public static extern Int32 HideCaret(Int32 hwnd);
private bool allow;
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint="ShowCaret", ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
public static extern Int32 ShowCaret(Int32 hwnd);
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint="CreateCaret", ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
public static extern Int32 CreateCaret(Int32 hwnd, Int32 hBitmap, Int32 nWidth, Int32 nHeight);
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint="SetCaretPos", ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
public static extern Int32 SetCaretPos(Int32 x, Int32 y);

string txt = null;

public Color color
{
get
{
return clr;
}
}


public Int16 penWidth
{
get
{
return pWidth;
}
set
{
pWidth = value;
nPen.Width = pWidth;
}
}
public void DrawPath(MouseEventArgs e) //path
{

}

public void DrawBrush(MouseEventArgs e) //brush
{

}
public void DrawLine(MouseEventArgs e) //line
{

}
private void SetLineW(Int16 MyW)
{
if (MyW < 1)
{
MyW = 1;
}
penWidth = MyW;

}
public void DrawRectangle(System.Windows.Forms.MouseEventArgs e) //rectangle
{
xLoc = 0;
yLoc = 0;

if (e.X > StartX)
{
BoxWidth = e.X - StartX;
xLoc = StartX;
}
else
{
BoxWidth = StartX - e.X;
xLoc = e.X;
}

if (e.Y > StartY)
{
BoxHeight = e.Y - StartY;
yLoc = StartY;
}
else
{
BoxHeight = StartY - e.Y;
yLoc = e.Y;
}
// DrawArea.CreateGraphics().DrawRectangle(nPen, xLoc, yLoc, BoxWidth, BoxHeight);
// DrawArea.Refresh();
}
public void DrawEllipse(System.Windows.Forms.MouseEventArgs e) //ellipse
{
xLoc = 0;
yLoc = 0;

if (e.X > StartX)
{
BoxWidth = e.X - StartX;
xLoc = StartX;
}
else
{
BoxWidth = StartX - e.X;
xLoc = e.X;
}

if (e.Y > StartY)
{
BoxHeight = e.Y - StartY;
yLoc = StartY;
}
else
{
BoxHeight = StartY - e.Y;
yLoc = e.Y;
}

// DrawArea.CreateGraphics().DrawEllipse(nPen, xLoc, yLoc, BoxWidth, BoxHeight);

//DrawArea.Refresh();
}
public void Eraser(System.Windows.Forms.MouseEventArgs e) //eraser
{
DrawArea.Refresh();
DrawArea.CreateGraphics().FillRectangle(Brushes.White, e.X - 1, e.Y, penWidth, penWidth);
DrawArea.CreateGraphics().DrawRectangle(Pens.Black, e.X - 1, e.Y, penWidth, penWidth);
}
private void Form1_Load(object sender, EventArgs e)
{
//color = Color.Black;
bmp2 = new Bitmap(DrawArea.Width, DrawArea.Height);
g2 = Graphics.FromImage(bmp2);
g2.SmoothingMode = SmoothingMode.AntiAlias;
}

private void DrawArea_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDraw = true;
StartX = e.X;
StartY = e.Y;

if (dmode == dModes.Text) //if text mode is selected it creates a caret on the clicked position
{

pF = new PointF((float)(e.X), (float)(e.Y - FontHeight / 2.0));
if (pF.Equals(pFOld))
{
}
else
{
allow = true;
}
DrawArea.Focus();

CreateCaret(DrawArea.Handle.ToInt32(), 0, 2, this.FontHeight);
//SetCaretPos(pF.X, pF.Y);
ShowCaret(DrawArea.Handle.ToInt32());
}

}
}

private void DrawArea_MouseMove(object sender, MouseEventArgs e)
{
if (isDraw)
{
switch (dmode)
{
case dModes.Ellipse:

DrawArea.CreateGraphics().DrawEllipse(nPen, xLoc, yLoc, BoxWidth, BoxHeight);
break;
case dModes.Line:
EndX = e.X;
EndY = e.Y;
// DrawArea.Refresh();
DrawArea.CreateGraphics().DrawLine(nPen, StartX, StartY, EndX, EndY);
break;
case dModes.Brush:
mpath.AddLine(e.X, e.Y, e.X, e.Y);
DrawArea.CreateGraphics().DrawPath(nPen, mpath);
break;
case dModes.Rectangle:


DrawArea.CreateGraphics().DrawRectangle(nPen, xLoc, yLoc, BoxWidth, BoxHeight);
break;
case dModes.Path:
EndX = e.X;
EndY = e.Y;


//DrawArea.Refresh();

DrawArea.CreateGraphics().DrawLine(nPen, StartX, StartY, EndX, EndY);
break;
case dModes.Eraser:
Eraser(e);
g2.FillRectangle(Brushes.White, e.X, e.Y, pWidth, pWidth);
break;



}
}
}

private void DrawArea_MouseUp(object sender, MouseEventArgs e)
{
isDraw = false;

switch (dmode)
{
case dModes.Ellipse:

g2.FillEllipse(new SolidBrush(clr), xLoc, yLoc, BoxWidth, BoxHeight);
break;

case dModes.Line:
g2.DrawLine(nPen, StartX, StartY, EndX, EndY);
break;
case dModes.Brush:
g2.DrawPath(nPen, mpath);
mpath.Reset();
break;
case dModes.Rectangle:

g2.DrawRectangle(nPen, xLoc, yLoc, BoxWidth, BoxHeight);
break;

case dModes.Path:
mpath.AddLine(StartX, StartY, e.X, e.Y);
g2.DrawPath(nPen, mpath);
// mpath.Reset();
break;
case dModes.Text:
if (allow)
{
g2.DrawString(txt, this.Font, new SolidBrush(clr), pFOld);
}
allow = false;
txt = "";
//tbox.Clear()
break;
}

DrawArea.BackgroundImage = bmp2;
}

private void DrawArea_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{


}

private void button1_Click(object sender, EventArgs e)
{
dmode = dModes.Ellipse;
mpath.Reset();
hide_Caret();
}

private void button2_Click(object sender, EventArgs e)
{
dmode = dModes.Rectangle;
mpath.Reset();
hide_Caret();
}

private void button7_Click(object sender, EventArgs e)
{
dmode = dModes.Line;
mpath.Reset();
hide_Caret();
}

private void button4_Click(object sender, EventArgs e)
{
dmode = dModes.Brush;
mpath.Reset();
hide_Caret();
}

private void button5_Click(object sender, EventArgs e)
{
dmode = dModes.Path;
hide_Caret();
}

private void button6_Click(object sender, EventArgs e)
{
dmode = dModes.Eraser;
hide_Caret();
}
public object hide_Caret() //hides the caret
{
if (txt != "")
{
g2.DrawString(txt, this.Font, new SolidBrush(clr), pFOld);
}
DrawArea.BackgroundImage= bmp2;
allow = false;
HideCaret(DrawArea.Handle.ToInt32());
txt = "";
//INSTANT C# NOTE: Inserted the following 'return' since all code paths must return a value in C#:
return null;
}
private void DiColor_Paint(object sender, PaintEventArgs e)
{

}

private void DiColor_MouseClick(object sender, MouseEventArgs e)
{
ColorDialog MyDC = new ColorDialog();
DialogResult Dr = MyDC.ShowDialog();
if (Dr == DialogResult.OK && MyDC.Color != null)
{
this.clr = MyDC.Color;

DiColor.BackColor = clr;

}
}

private void trackBar1_Scroll(object sender, EventArgs e)
{
SetLineW(Convert.ToInt16(trackBar1.Value));
}

private void button3_Click(object sender, EventArgs e)
{
dmode = dModes.Text;
mpath.Reset();
}

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
txt += e.KeyChar;
this.Refresh();
//INSTANT C# TODO TASK: The 'On Error Resume Next' statement is not converted by Instant C#:

if (e.KeyChar == '\b') //backspace
{
txt = txt.Substring(0, txt.Length - 2);
e.Handled = true;
}
g2.PageUnit = GraphicsUnit.Pixel;
//SetCaretPos(pF.X + g2.MeasureString(txt, new Font("arial", 8)).Width, pF.Y);
DrawArea.CreateGraphics().DrawString(txt, this.Font, new SolidBrush(clr), pF.X, pF.Y);
pFOld = pF;
}

private void DrawArea_Paint(object sender, PaintEventArgs e)
{



}

}
}
AnswerRe: draw problem Pin
Richard MacCutchan21-Feb-11 12:45
mveRichard MacCutchan21-Feb-11 12:45 
AnswerRe: draw problem Pin
Luc Pattyn21-Feb-11 13:20
sitebuilderLuc Pattyn21-Feb-11 13:20 
Questionfind an item in list collection to add or update Pin
arkiboys21-Feb-11 4:40
arkiboys21-Feb-11 4:40 
AnswerRe: find an item in list collection to add or update Pin
_Erik_21-Feb-11 4:46
_Erik_21-Feb-11 4:46 
GeneralRe: find an item in list collection to add or update Pin
arkiboys21-Feb-11 4:52
arkiboys21-Feb-11 4:52 
GeneralRe: find an item in list collection to add or update Pin
_Erik_21-Feb-11 5:03
_Erik_21-Feb-11 5:03 
GeneralRe: find an item in list collection to add or update Pin
arkiboys21-Feb-11 5:07
arkiboys21-Feb-11 5:07 
GeneralRe: find an item in list collection to add or update Pin
_Erik_21-Feb-11 5:15
_Erik_21-Feb-11 5:15 
GeneralRe: find an item in list collection to add or update Pin
Luc Pattyn21-Feb-11 5:09
sitebuilderLuc Pattyn21-Feb-11 5:09 
GeneralRe: find an item in list collection to add or update Pin
_Erik_21-Feb-11 5:14
_Erik_21-Feb-11 5:14 
AnswerRe: find an item in list collection to add or update Pin
Luc Pattyn21-Feb-11 5:11
sitebuilderLuc Pattyn21-Feb-11 5:11 
AnswerRe: find an item in list collection to add or update Pin
#realJSOP21-Feb-11 6:03
professional#realJSOP21-Feb-11 6:03 
GeneralRe: find an item in list collection to add or update Pin
Orcun Iyigun21-Feb-11 13:37
Orcun Iyigun21-Feb-11 13:37 
GeneralRe: find an item in list collection to add or update Pin
Pete O'Hanlon22-Feb-11 1:36
mvePete O'Hanlon22-Feb-11 1:36 
GeneralRe: find an item in list collection to add or update Pin
#realJSOP22-Feb-11 3:31
professional#realJSOP22-Feb-11 3:31 
QuestionAT commands in c# Pin
aeman21-Feb-11 3:30
aeman21-Feb-11 3:30 
AnswerRe: AT commands in c# Pin
Thomas Krojer21-Feb-11 5:40
Thomas Krojer21-Feb-11 5:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.