|
Does anyone know how i can vertical align the lines in a richtesxtbox? pls help
|
|
|
|
|
I am trying to draw a rubberband rectangle using one of the methods suggested in this forum. My problem is: after drawing the rectangle, if I move another window (for example a messagebox) over the rectangle (ruberband rectangle drawn earlier) part of this rectangle is not getting pained properly. Any help is highly appreciated.
The code that I am using is given below.
<br />
<br />
using System;<br />
using System.Windows.Forms;<br />
using System.Drawing;<br />
<br />
namespace RubberbandShape<br />
{<br />
class MainForm : System.Windows.Forms.Form<br />
{<br />
public MainForm()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
void InitializeComponent() {<br />
this.button1 = new System.Windows.Forms.Button();<br />
this.SuspendLayout();<br />
this.button1.Location = new System.Drawing.Point(323, 256);<br />
this.button1.Name = "button1";<br />
this.button1.Size = new System.Drawing.Size(75, 23);<br />
this.button1.TabIndex = 0;<br />
this.button1.Text = "button1";<br />
this.button1.UseVisualStyleBackColor = true;<br />
this.button1.Click += new System.EventHandler(this.button1_Click);<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(401, 282);<br />
this.Controls.Add(this.button1);<br />
this.Name = "MainForm";<br />
this.Text = "Rubber Band Shape Drawing";<br />
this.Paint += new System.Windows.Forms.PaintEventHandler(this.MainForm_Paint);<br />
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseUp);<br />
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseMove);<br />
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseDown);<br />
this.ResumeLayout(false);<br />
<br />
}<br />
<br />
[STAThread]<br />
public static void Main(string[] args)<br />
{<br />
Application.Run(new MainForm());<br />
}<br />
<br />
private bool mouseDown = false;<br />
private bool mouseMoving = false;<br />
private bool haveRect = false;<br />
private int XDown;<br />
private int YDown;<br />
private int oldX;<br />
private Button button1;<br />
private int oldY;<br />
<br />
void MainForm_MouseDown(object sender,<br />
System.Windows.Forms.MouseEventArgs e)<br />
{<br />
if( e.Button == MouseButtons.Left )<br />
{<br />
mouseDown = true;<br />
XDown = e.X;<br />
YDown = e.Y;<br />
mouseMoving = false;<br />
}<br />
else if( e.Button == MouseButtons.Right )<br />
{<br />
if( haveRect )<br />
{<br />
haveRect = false;
Invalidate();
}<br />
}<br />
}<br />
<br />
void MainForm_MouseMove(object sender,<br />
System.Windows.Forms.MouseEventArgs e)<br />
{<br />
if( mouseDown )<br />
{<br />
if( mouseMoving )<br />
RubberRectangle( XDown, YDown, oldX, oldY );<br />
RubberRectangle( XDown, YDown, e.X, e.Y );<br />
mouseMoving = true;<br />
oldX = e.X;<br />
oldY = e.Y;<br />
}<br />
}<br />
<br />
void MainForm_MouseUp(object sender,<br />
System.Windows.Forms.MouseEventArgs e)<br />
{<br />
mouseDown = false;<br />
mouseMoving = false;<br />
haveRect = true;<br />
}<br />
<br />
private void RubberRectangle( int X1, int Y1, int X2, int Y2 )<br />
{<br />
System.Drawing.Graphics g = Graphics.FromHwnd( this.Handle );<br />
<br />
RubberbandRectangle rect<br />
= new RubberbandRectangle();<br />
rect.DrawXORRectangle( g, X1, Y1, X2, Y2 );<br />
}<br />
<br />
void MainForm_Paint(object sender,<br />
System.Windows.Forms.PaintEventArgs e)<br />
{ <br />
Graphics g = Graphics.FromHwnd( this.Handle );<br />
<br />
if( haveRect )<br />
RubberRectangle( XDown, YDown, oldX, oldY );<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
MessageBox.Show("err yty");<br />
}<br />
<br />
} <br />
<br />
public enum PenStyles<br />
{<br />
PS_SOLID = 0,<br />
PS_DASH = 1,<br />
PS_DOT = 2,<br />
PS_DASHDOT = 3,<br />
PS_DASHDOTDOT = 4<br />
}<br />
public class RubberbandRectangle<br />
{<br />
private int NULL_BRUSH = 5;<br />
private int R2_XORPEN = 7;<br />
private PenStyles penStyle;<br />
private int BLACK_PEN = 0;<br />
<br />
public RubberbandRectangle()<br />
{<br />
penStyle = PenStyles.PS_DOT;<br />
}<br />
<br />
public PenStyles PenStyle<br />
{<br />
get { return penStyle; }<br />
set { penStyle = value; }<br />
}<br />
<br />
public void DrawXORRectangle(Graphics grp,<br />
int X1, int Y1, int X2, int Y2)<br />
{<br />
IntPtr hdc = grp.GetHdc();<br />
<br />
IntPtr gdiPen = CreatePen(penStyle,<br />
1, BLACK_PEN);<br />
<br />
SetROP2(hdc, R2_XORPEN);<br />
<br />
IntPtr oldPen = SelectObject(hdc, gdiPen);<br />
<br />
IntPtr oldBrush = SelectObject(hdc,<br />
GetStockObject(NULL_BRUSH));<br />
<br />
Rectangle(hdc, X1, Y1, X2, Y2);<br />
<br />
SelectObject(hdc, oldBrush);
SelectObject(hdc, oldPen);<br />
DeleteObject(gdiPen);
<br />
grp.ReleaseHdc(hdc);<br />
}<br />
<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern int SetROP2(<br />
IntPtr hdc,
int enDrawMode
);<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern IntPtr CreatePen(<br />
PenStyles enPenStyle,
int nWidth,
int crColor
);<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern bool DeleteObject(<br />
IntPtr hObject
);<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern IntPtr SelectObject(<br />
IntPtr hdc,
IntPtr hObject
);<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern void Rectangle(<br />
IntPtr hdc,
int X1,
int Y1,
int X2,
int Y2
);<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern IntPtr GetStockObject(<br />
int brStyle
);<br />
<br />
private static int RGB(int R, int G, int B)<br />
{<br />
return (R | (G << 8) | (B << 16));<br />
}<br />
}<br />
}<br />
<br />
Cheers,
Prasad
|
|
|
|
|
Don't paste your whole code. I don't think it will be read. Try to find out which part of it generates that problem and then ask for help in regards with that specific problem giving as an example your code fragment.
I am fighting against the Universe...
Reference-Rick Cook
|
|
|
|
|
u must clear de background in the graphic object
void MainForm_Paint(object sender,<br />
System.Windows.Forms.PaintEventArgs e)<br />
{<br />
Graphics g = Graphics.FromHwnd(this.Handle);<br />
<br />
if (haveRect)<br />
{<br />
g.Clear(BackColor);<br />
RubberRectangle(XDown, YDown, oldX, oldY);<br />
}<br />
}
|
|
|
|
|
Cuciu,
Thanks for the suggestion. My problem is partially solved. Still the following problem persists. If I colse the messagebox, while it is on the rubber recatngle, that part is not redrawn.
Further, the suggested method doesn't work if I use "e.Graphics.Clear(BackColor)".
Could you please explain why?
My main problem is the Following:
<br />
private void FormMap_Paint(object Sender, PaintEventArgs e)<br />
{<br />
e.Graphics.Clear(this.BackColor);<br />
e.Graphics.DrawImage(Map.BMP, 0, 0);<br />
DrawFenceline();<br />
HiliteOn();<br />
}<br />
my Map object is stored on a bitmap. In form paint event I am drawing bitmap on to form. Then a fenceline is drawn (a region of rubberband lines) which is used to select a group of objects.
However, when I display a message box (or other form) on this form I am having problems with rubberband lines as explained earlier.
Any help to overcome this problem?
Regards,
Prasad
|
|
|
|
|
When you show your messagebox, call Invalidate() afterwards to force a paint event, which will draw your image again
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I know that GDI+ doesn't offer XOR drawing, but this still looks far too messy to me. What's wrong with just drawing a black ( or white, or whatever ), box in your paint event ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi
I have an Excel sheet, has 4 columns. In the first column there is an industry code, which contains both numeric and alphanumeric chararcters. I'm not able to read the values to the dataset if the value is alphabets. For eg. if the value is 1,2,3,4 etc.. it will read. But if the value is 1a, 2b, 3e, 4d etc. then it will read as null. Anybody has any solution for these? Any help would be great. I'll post my code below:
OleDbCommand MyCommand;
OleDbConnection MyConnection;
MyConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=C:\\Projects\\LiquidCreditChains\\CreditCurveMapping.xls;Extended Properties=Excel 8.0;");
if (MyConnection.State != ConnectionState.Closed)
MyConnection.Close();
else
MyConnection.Open();
DataTable dtSector = new DataTable("SectorChains");
objds.Tables.Add(dtSector);
DataColumn dc1 = new DataColumn("Indust_Code");
dc1.DataType = System.Type.GetType("System.String");
dtSector.Columns.Add(dc1);
DataColumn dc2 = new DataColumn("Indust_Number");
dc2.DataType = System.Type.GetType("System.Int64");
dtSector.Columns.Add(dc2);
DataColumn dc3 = new DataColumn("MappingDescription");
dc3.DataType = System.Type.GetType("System.String");
dtSector.Columns.Add(dc3);
DataColumn dc4 = new DataColumn("SubDescription");
dc4.DataType = System.Type.GetType("System.String");
dtSector.Columns.Add(dc4);
DataColumn dc5 = new DataColumn("Mapping_Curve");
dc5.DataType = System.Type.GetType("System.String");
dtSector.Columns.Add(dc5);
MyCommand = new OleDbCommand("select * from [Sheet1$]", MyConnection);
OleDbDataReader dr1 = MyCommand.ExecuteReader();
while (dr1.Read())
{
DataRow newChainRow = objds.Tables[0].NewRow();
newChainRow["Indust_Code"] = dr1[0].ToString();
newChainRow["Indust_Number"]=dr1[1].ToString();
newChainRow["MappingDescription"] = dr1[2].ToString();
newChainRow["SubDescription"]= dr1[3].ToString();
newChainRow["Mapping_Curve"] = dr1[4].ToString();
objds.Tables[0].Rows.Add(newChainRow);
}
Any help in this regard would be great!!
Thanks
Meeram395
|
|
|
|
|
|
|
Hi to everybody
I have DB as dat file.I've paging concept works fine.Problem is when i delete or edit or add records, it is showing the first page on data grid( if i have 50 records-per page 20).I need if the record no 45 is updated OR deleted it has to show the current page i.e., 3rd page.I have not used connection string.Plz help me thanks in advance.
|
|
|
|
|
Hi,
As per my understanding after every edit or add you must be binding your grid somewhere and i think you are not setting its current page index...
Hope it will work...
Thanks
~Anuj~
|
|
|
|
|
i have not used connection string.I've used .dat file as DB, READING AND WRITING DATAS IN TMP TABLE.If anyone has code sample it will be more helpful.Thanks in advance.
|
|
|
|
|
Hi,
I am creating a windows application,that contains a folder,with 5 files. how to programaticlly get the names of all the files in that folder(getting names of all the contents of that folder)
Say folder name is "MyXMLFolder" .It contains elemnts as
-Customer.xml
-Employee.Xml
-Bank.xml
I want c# coding to get all the names of the files in "MyXMLFolder" folder
-- modified at 2:13 Monday 13th August, 2007
|
|
|
|
|
DirectoryInfo dir = new DirectoryInfo(@"F:\MyFolder");<br />
FileInfo[] files = dir.GetFiles("*.*");<br />
<br />
Foreach(FileInfo f in files )<br />
{<br />
Console.WriteLine("Name is : {0}", f.Name);<br />
Console.WriteLine("Length of the file is : {0}", f.Length);<br />
Console.WriteLine("Creation time is : {0}", f.CreationTime);<br />
Console.WriteLine("Attributes of the file are : {0}",<br />
f.Attributes.ToString());<br />
}
Ref:
Working with Files in C#[^]
File Information using C#[^]
Hope it helps.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
Thank you, for detailed description,
working
|
|
|
|
|
Hi,
You need to use the System.IO namespace. The following code will get you all files in a folder as strings in a string array, including the folder path:
string[] files = Directory.GetFiles(@"c:\MyXMLFolder");
Everything you will need to work with files can be found in System.IO.
Regards,
Toby
|
|
|
|
|
|
Hello Friends,
I had generated the crystal report.I want to change the connection string but I am unable to do so . Actually their are two database one is testing database and other is live database. So I need to change the connection string.
But I am unable to do so.
Regards,
rahul saini
|
|
|
|
|
Open your crystal report and on the left hand side you will find Field Explorer, under that you will find Database Fields, right click on that and click on Database Expert and the Database Expert Dialog box will open from there choose Project Data or Create New Connection, according to your need.
Thanks
Imran
|
|
|
|
|
Hello Imran,
If I choose new connection then all the feilds that i had drag from the previous table will delete.
Regards,
rahul saini
|
|
|
|
|
Ya the feilds will get deleted, do one thing what ever feilds you have dragged earlier, select all the feilds and copy it and when u create new report just paste all the feilds as it is, hope this may help.
Thanks
Imran
|
|
|
|
|
But Imran I had aroung 10 to 15 reports.
How is it possible to edit every time.
Is their any other sollution , through coding.
Regards,
rahul saini
|
|
|
|
|
I think u must have written some class where u have defined the connection string, change the connection string from there first, what ever new connection string you want. Now in report section u might be using Crystal Report Viewer, so in that Form Load write code like this, according to your table name and class name.
I hope this will help you.
private void CreateReport()
{
this.datcMarketData.getdatafrmdatabase();
JobMarketReport report = new JobMarketReport();
report.SetDataSource(datcMarketData.dSet);
crystalReportViewer1.ReportSource = report;
}
Thanks
Imran
|
|
|
|
|
Hi I am developing an windows application in C#.Net(2003).
My form has some textboxes, button and a datagrid. The functionality of the application is in a DLL.
The functionality is like this.
Enter input parameters in text boxes (one parameter belongs to time)
Click Start Button ==> the control goes to the DLL. based up on the time it has to perform the functionality.(suppose for example if we give 4 hours)
After completing a specific period (for example say 1hour) we have to enter a row in the data grid. THis action is done from the form.
For this i am using a timer in the form, on the elapsed time i am entering a row to the data grid by using a datatable.
Also notice one thing, I am using notify icon to show my application in system tray when it is minimized. If the addition of row is done when the form is in the minimized state, if i double click on the icon in the system tray then it is giving an exception "Object reference is not set" from the code in the notify icon Click. In this i am using a statement
this.ShowInTaskbar = true;
when the form is in normal state, adding a row to grid is happening correctly but the form is not responding after performing this action.
Any one please help me.
Thanks in Advance
Thanks and Regards
Ramu
|
|
|
|
|