|
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)<br />
{<br />
PaintEventArgs myPaintArgs = new PaintEventArgs (e.Graphics, new Rectangle(0,0,datagrid1.Width,datagrid1.Height));<br />
this.InvokePaint(dg, myPaintArgs);<br />
}
this is the coding i used to print out datagrid, the X and Y is set to 0 and 0, the datagrid print out correctly at exactly upper left corner of the paper.
then i modify the coding.
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)<br />
{<br />
PaintEventArgs myPaintArgs = new PaintEventArgs (e.Graphics, new Rectangle(50,50,datagrid1.Width,datagrid1.Height));<br />
this.InvokePaint(dg, myPaintArgs);<br />
}
i change the cordinates to 50,50, but y the datagrid still print at the same position for cordinates 0,0??i do not wan the datagrid to be printed at that position!anyone can help me out with this??Thz!
|
|
|
|
|
You could create a bitmap with the needed dimension, create a Graphics object for it, paint the grid to this bitmap and finally draw the bitmap onto the page:
Bitmap b = new Bitmap(datagrid1.Width,datagrid1.Height);
using (Graphics bg = GraphicsFromImage(b)) {
PaintEventArgs myPaintArgs = new PaintEventArgs (bg , new Rectangle(0,0,datagrid1.Width,datagrid1.Height));
this.InvokePaint(dg, myPaintArgs);
}
e.Graphics.DrawImageUnscaled(b, 50, 50);
|
|
|
|
|
thz man!the coding works for me.. but there is another problem, my datagrid has been loaded with a datatable contains 31 records, under screen resolution of 1024*768, the screen is able to show and print out all the records, but if user change screen resolution to 800*600, the records that can show in one screen is only 21 records, the rest of the records needed to be scroll down to view, then the datagrid printed out only contains 21 records that can be shown on the screen... wat should i do??
|
|
|
|
|
I´m writing a little library, where my main object MainObject contains some properties and a collection of ElementBase (abstract) objects.
I actually have two derived classes from ElementBase , each of which has properties, some common to the base class, others specific to the type.
I would like to save this MainObject to an XML with all of its elements, according to:
- Smallest file size possible. I don´t need uncessesary properties, only the important ones (my properties, not those from base clasess)
- Backward compatibily. I want a new version to read old version successfully and the other way around. Properties not present should be defaulted, and newer properties ignored.
- Support for different types of ElementBase-derivatives, both existing and future.
My idea of the XML file was something like this:
<MainObject property1="x" property2="y">
<Element type="DerivedElement1">
<property1>value</property1>
</element>
<Element type="DerivedElement2">
<OtherProperty>value</OtherProperty>
</element>
<MainObject> So, the first question, what do you think? is this flexible enough?
And the second question, how do I write the XML to the file? I've been checking the System.Xml namespace and there are a lot of things in there. I could use an XmlTextWriter or an XmlDocument . I saw also XmlDataDocument but I believe it is for reading/writing a DataSet to XML, am I right?
I don´t really need code samples (they sure can help) but just an pointer on what's the easiest, yet powerful enough, way of achieving what I want.
{EDIT: and of course, how would I read the file to recreate the objects? )
Thanks in advance,
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I'd use the XMLTextWriter, seeing as you're creating the entire document, rather than loading/manipulating one.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
hi Luis,
I'd second Christian's advice. XmlTextWriter is fastest way how to write XML document. It's quite easy to use as well.
Luis Alonso Ramos wrote:
I saw also XmlDataDocument but I believe it is for reading/writing a DataSet to XML, am I right?
yeah.
Luis Alonso Ramos wrote:
and of course, how would I read the file to recreate the objects?
with XmlTextReader
OTOH, why not to use Serialization[^]? I belive that you can set (with attibutes) what should be serialized into XML and what shouldn't. However I don't know how it would fit into backward compatibility concept. (maybe there isn't problem, I really don't know)
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
dnh wrote:
why not to use Serialization[^]? I belive that you can set (with attibutes) what should be serialized into XML and what shouldn't. However I don't know how it would fit into backward compatibility concept.
Yeah, I had thought about adding a Serializable attribute to the classes, but I don't want every property serialized (especially those from base classes which I can't modify.) Also, for example, I have a Font object, and I want only to save font family, size, not all of it.
Thanks,
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
First I would like to thank you for taking your time to read my questions... I really need some helps here.
Bascially I want to write a program in which users can design their layouts.
So let us say I got a textbox, and I want it be to able to be dragged around the main window or resize it... and i want to have like a rectangle box around it when I click on it..
How am I going to start?
I tried using the events mouseUp, mouseDown to move the objects.. but I cant find out how to draw a rectangle around the textbox or how to resize it..
could you please help me out? Thank you so much.
Elapid For The Win
|
|
|
|
|
Ooops - I thought I was in C++ land for a moment....
Your form has a paint event, override it to do any drawing you might want to do on the screen.
Controls have a Location and a Size property. You need to change those to move or resize the controls.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
how do i draw a rectangle thinige around the textbox? you know like in Visual Studio, when you click on an object, there are like 6 small squares at the corners of an object which then let you resize that object..
Elapid For The Win
|
|
|
|
|
Like I said, in OnPaint. You need to draw outside the bounds of the control, so the control can't draw it. You need to create hotspots, and store them in an array. Use them to draw the little boxes, and also to check when someone clicks if they are inside one.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thank you Christian.
I will work on it
Elapid For The Win
|
|
|
|
|
How do I obtain the current mouse position?
Thank you
Elapid For The Win
|
|
|
|
|
Use the MouseDown or MouseUp event-handler for the text-box (or other control) for knowing the current mouse location. For example,
private void textBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
Point mouseDownLocation = new Point(e.X, e.Y);
}
|
|
|
|
|
Hi,
I want to add the line spacing between two text lines. But in MSDN there is only Font.Height attribute which serve as the following,
the first line
|--------------|
Font.Height |____________|}--->line spacing
|the secondline
How to improve the line spacing height? Please help me ?
welspring
hope for help
|
|
|
|
|
|
thanks for your answer! But now I have another question. In a RichTextBox control , I want to use your method to add the absolute line spacing between two lines. I have overrided the Method OnPaint, just like this,
public class MyRichTextBox : RichTextBox
{
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
e.Graphics.DrawString(
"This is the first line",
myFont,
Brushes.Black,
new PointF(0, 0));
float height = myFont.GetHeight(e.Graphics);
e.Graphics.DrawString(
"This is the second line",
myFont,
Brushes.Black,
new PointF(0, height+x));
}
But i doesn't work, what should I do. Is it right to override the OnPaint function? Please help me .
welspring
hope for help
|
|
|
|
|
|
In fact, the code cited by me works if you want to show text on some form or some other controls. However, in a RichTextBox, it will not work directly because display of text is managed internally. I personally checked the above method to draw the text on the face of a form by overriding the "OnPaint" and by giving "x" different values of say 50 or 100. It worked perfectly alright.
Now coming back to RichTextBox, I may mention that in the MFC days, in VC++ we had the Rich Edit Control classes, including CRichEditView class which in its 2.0 and 3.0 versions exposed a structure called "PARAFORMAT2 Structure", the contents of which can be seen at the following link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/paraformat2.asp[^]
I am just reproducing the basic structure of this structure for ready reference:
typedef struct _paraformat {
UINT cbSize;
DWORD dwMask;
WORD wNumbering;
WORD wEffects;
LONG dxStartIndent;
LONG dxRightIndent;
LONG dxOffset;
WORD wAlignment;
SHORT cTabCount;
LONG rgxTabs[MAX_TAB_STOPS];
LONG dySpaceBefore;
LONG dySpaceAfter;
LONG dyLineSpacing;
SHORT sStyle;
BYTE bLineSpacingRule;
BYTE bOutlineLevel;
WORD wShadingWeight;
WORD wShadingStyle;
WORD wNumberingStart;
WORD wNumberingStyle;
WORD wNumberingTab;
WORD wBorderSpace;
WORD wBorderWidth;
WORD wBorders;
} PARAFORMAT2;
#define wEffects wReserved
You can notice that one of the members is "dyLineSpacing" which was used in CRichEditView in MFC for changing line spacing as decided by the value of the other member-variable "bLineSpacingRule".
However, it appears that the aforesaid "PARAFORMAT2" is not exposed in the RichTextBox control in the .NET framework, though to be fair, I admit that I did not search its features exhaustively.
One possible solution could be to locate the previous Rich Edit Control's dll (riched20.dll or any later version) on the system and add a reference in your project and then use the said "PARAFORMAT2" structure. Or alternatively, please try to read the detaild literature in MSDN on RichEditBox in .NET if such a functionality is directly made available.
|
|
|
|
|
whether or no, I should thanks of you. From what you have mentioned, I learned much knowledge. Thanks a lot!
welspring
hope for help
|
|
|
|
|
Hi,
i have a problem with setting the active directory of an aplication
For example when the aplication is like in a folder "c:\myprog.exe"; and in the aplication an openfiledialog is opened and a file selected from a folder like "d:\file.txt" after in the code when i try to save a file by giving only filename the file is saved in folder d:\ instead of the folder c:\where the aplication is located and run from.
it there a way to prevent this change of active directory?
|
|
|
|
|
No there isn't.
What you should be doing is not saving files or anything else by using just a filename. You should ALWAYS, and I mean ALWAYS, use full path specifications when working with files.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello all:
I'm relatively new to c# and i would like to know how to populate a listView with data from an access db. The db only has one table. I need to pull out each memberNumber First and Last names and address. These values are included as my column headers in my listView.
If anyone can help me out i would appreciate it.
|
|
|
|
|
Something like this:
using System.Data.OleDb;
.
.
.
void FillList()
{
OleDbConnection conn = new OleDbConnection("connection string"))
OleDbCommand cmd = new OleDbCommand("SELECT * FROM TableName;", conn))
OleDbDataReader rdr = cmd.ExecuteReader();
while(rdr.Read())
{
ListViewItem item = new ListViewItem();
item.Text = ((int) rdr["MemberNumber"]).ToString();
item.SubItems.Add((string) rdr["FirstName"]);
item.SubItems.Add((string) rdr["LastName"]);
listView.Items.Add(item);
}
rdr.Close();
} What you are doing is initializing a data reader with the resultset from the SELECT query. For every record, you add an item to the list view, with the member number on the first column, and then the first name and last name.
I've left out all error checking, such as in case the connection couldn't be openned, or the some of the fields were null. But that's the general idea.
Don't forget to check the docs to learn more.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Thanks alot Luis. That was a big help.
I am having some trouble opening the connection string. Im getting a runtime error declaring that it is set to close. Ive tried a bunch of things but cant seem to get it.
If you have any thoughts there id appreciate it. Thanks again.
|
|
|
|
|