|
You will first need to take a look at the Bitmap class and also the Graphics class.
First you need to create a new bitmap and make it white:
Bitmap bmp = new Bitmap(w,h);<br />
<br />
using(Graphics g = Graphics.FromImage(bmp))<br />
{<br />
<br />
g.FillRectangle(Brushes.White,0,0,bmp.Width,bmp.Height);<br />
<br />
int x = (w - bmp.Width) / 2;<br />
int y = (h - bmp.Height) / 2;<br />
<br />
g.DrawImage(original_bmp,x,y);<br />
}<br />
<br />
<br />
I have not tested this, but it should give you an idea.
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Thanks, that seems to work. The only odd thing was that I had to use DrawImage(img,x,y,width,height) otherwise it did strange things to the image, sometimes it appeared tiny, other time blown up. Very strange.
|
|
|
|
|
Wjousts wrote:
Thanks, that seems to work.
Glad, I could be of help.
-Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
|
Hi!
I'm searching a method to create my own form design environment.
Anybody know how to in C#??
Tnh a lot!
|
|
|
|
|
Sharp Develop is a free IDE written in C#. Check out its source code. http://www.icsharpcode.net/OpenSource/SD/Default.aspx[^]
"De most compwehensive image seawch on de web." - Google in Elmer Fudd Language "But a fresh install - it's like having clean sheets" - Chris Maunder Lounge 3 Mar '03
Jonathan 'nonny' Newman Web Designer, Programmer, Lover, Visionary Leader...
Homepage [www.nonny.com] [^]
|
|
|
|
|
Hi all,
I have to write a selection control like you have in Paint for my program (you know, to select parts of the image you're working on in Paint). I've searched all over the web to find such a control, but it looks like it doesn't exist yet, so I have to write it myself. I already have some ideas how to get it working, but I know almost for sure that they will be way too slow. Does anybody have an idea how to make such a control?
Thanks in advance,
Joost Huizinga
|
|
|
|
|
Please take a look at the ControlPaint.DrawReversibleFrame method. That will help you
Smitha
The future belongs to those who believe in the beauty of their dreams.
--Eleanor Roosevelt
|
|
|
|
|
Hi,
This is one useful snippet I used.
private void DrawReversibleRect( Point p1, Point p2 )
{
Rectangle rc = new Rectangle();
if( p1.X < p2.X )
{
rc.X = p1.X;
rc.Width = p2.X - p1.X;
}
else
{
rc.X = p2.X;
rc.Width = p1.X - p2.X;
}
if( p1.Y < p2.Y )
{
rc.Y = p1.Y;
rc.Height = p2.Y - p1.Y;
}
else
{
rc.Y = p2.Y;
rc.Height = p1.Y - p2.Y;
}
Rectangle r = pictureBox1.RectangleToScreen(rc);
ControlPaint.DrawReversibleFrame(r,this.BackColor,FrameStyle.Dashed);
}
You can draw the reversiblerectangle in the MouseMove event.
HTH
Smitha
The future belongs to those who believe in the beauty of their dreams.
--Eleanor Roosevelt
|
|
|
|
|
Hi Smitha,
Thanks for your reply. I already found something like that, by setting some Pen properties and drawing a rectangle with the Graphics.DrawRectangle method I got the same. But thanks nevertheless, this way is much easier.
But drawing the selectioncontrol isn't my main problem. My main problem is the resizing of the control and setting the cursors depending on where they are. For example, when the cursor is within the control, the cursor has to be set to the SizeAll cursor. But if the cursor is in the middle dotted line of the rectangle (on the little square), the cursor has to be set to SizeNS if the cursor is on the upper or the bottom line, and to SizeWE if the cursor is on the right or the left line. And the corners also have their own cursors. Setting the cursor every time when the MouseMove event is fired depending on where the mouse is requires a lot of if's and it will be way too slow. So do you have an idea how to get that working without making the program very slow?
By the way, I'm not a very experienced programmer. So it could be I ask dumb questions .
Thanks in advance,
Joost
|
|
|
|
|
My MyDUMeter article mite be of some help. I use painting for range selection on the report graph. I think you are having the same performance problems I had.
http://www.codeproject.com/useritems/MyDUMeter.asp[^]
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Hi leppie,
Thanks for your reply, I think I know enough about the drawing stuff. The only thing left is assigning the right cursors, but I'll try some things myself first. Still, any comments on assigning the cursors are welcome!
Thanks in advance,
Joost
|
|
|
|
|
Hi Joost,
I have not tried it that way. But do post about it, if you succeed assigning cursors to the selection. Good luck!
Smitha
The future belongs to those who believe in the beauty of their dreams.
--Eleanor Roosevelt
|
|
|
|
|
Hello,
does anyone know how to align the Pen-Object correctly when drawing lines with the DrawLine() - Methode of the Graphics-Namespace?
The problem is, that when i draw a line with a width of e.g. 7 pixels from Point (0,10) to Point (100,10) the topmost/leftmost painted pixel is at (0,7) instead of (0,10). That is because the Pen-Object is positioned at the center of the line that should be drawn. But this behavior is bad when drawing borders of e.g. controls.
The PenAlignment-Property of the Pen-Object doesn't seem to work here, though it works with the DrawRectangle()-Methode. If i paint a rectangle with the startcorner at (0,10) and i set the PenAlignment to "Inset", the topmost/leftmost paintet pixel is at the "correct" location of (0,10).
Does anyone here know how to solve this problem?
Greetings
Armin
|
|
|
|
|
Line accuracy is troublesome when working in different mapping modes. Lines work fine when defining them in MM_TEXT (without scaling) but when using modes like MM_HIMETRIC and incorporating scaling, the MFC lines always insist on having the same screen coordinate width regardless of where they translate to from the mapping mode. Alignment problems because of this behaviour are most evident with endcaps when aligning horizontal and vertical lines. At different scales, a little overhang or underhang becomes evident. Consistency at all scales is nearly impossible to achieve.
Your question concerning the alignment can be approached by taking the line and offsetting it but you will find alignment with MFC Rectangles and Circles becomes problematic (especially with borders). I spent quite a few months addressing this issue and studying how other applications approach alignment and found that there are many schools of thought, all having pro's and con's.
When you need to leftalign and rightalign bottomalign and topalign geometric shapes, you will find that line thickness and your choice of righthanded, centered, and lefthanded lines complicate the process and will require some modifications to coordinates you feed to the drawing commands. I believe there are no "One size fits all" drawing routines that will accomodate every programmers needs. The MFC drawing commands are a good place to start but I would recommend calling those functions from within your own drawing functions that take your drawing approach into consideration.
|
|
|
|
|
I made Several userControls and one WinForm.
And I tried to attach userControls to WinForm from ToolBox at Design Time.
But, "System.NullReference Exception occurred"
When I did 'drag and drop' to do it.
I don't know Why it happened.
Is there anybody Help me??
|
|
|
|
|
Anyone had a look at COM+ from .NET using the Enterprise Services namspace?
I've been having a look, but when I override some of the functions in the ServicedComponent class (Construct & CanBePooled) from which I have to derive my new managed COM+ component, the compiler complains.
[Transaction(TransactionOption.Required)]
public class BusinessObject : ServicedComponent
{
public BusinessObject()
{
}
protected internal override bool CanBePooled()
{
return false;
}
protected internal override void Construct(string s)
{
}
public void DoWork()
{
ContextUtil.DeactivateOnReturn = true;
ContextUtil.MyTransactionVote = TransactionVote.Abort;
ContextUtil.MyTransactionVote = TransactionVote.Commit;
}
}
I've been looking at this example.on MSDN, but it uses the beta edition of VS.NET, and does not compile.
http://msdn.microsoft.com/msdnmag/issues/01/10/complus/default.aspx[^]
I managed to get the above compling by manually ammending the access modifiers, but it does not seem very slick, when you have the IDE overide a member, and create the code, to find it does not compile.
Changing to
protected override void Construct(string s)
{
}
works, but as I said not very slick. If this is the mest MS can do, then not much hope. .NET will only be of any use to code monkeys.
Quote from a clever bloke :
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
|
|
|
|
|
Hi, I need to store a word document in MSSQL database (in image field) from C# windows application!
How can I do it? I need to create some kind of binary readers or streams to get that file and then store it or I do not know?
|
|
|
|
|
Check out ADO.NET and BLOB fields on MSDN. BLOB standing for - binary large objects.
If your not familiar with ADO or ADO.NET.
You need to open a database connection, and then a Recordset (for ADO), or a DataAdapter and a DataSet for ADO.NET.
In ADO (native COM objects), an ADODB.Recorset object can be used to both open a table and a append or update records.
In ADO.NET this functionality is split between the DataAdapter (For speaking to the DB) and the DataSet objects (for programatically examining the data off line).
Good luck.
If your new use the ADO library, and the Recordset.Field.AppendChunk & GetChunk methods to load and extract binary data into an image field.
Quote from a clever bloke :
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
|
|
|
|
|
As you know, double clicking a word document (for example) will open MS Word and then open that document. If the document has no file associated to it, “open with” window will appear.
My question, is there a way in C# to imitate (or invoke) such functionality?
|
|
|
|
|
Not a good starting in this forum..I am still searcing and searching for an answer.. It seems I'll answer my self after few days (not bad!)..
|
|
|
|
|
Hi:
I am going to draw graphics in c#, and this process of drawing should be saved (probably with time and pixel). so later can replay the process of how the graphics to be drawn.
but i have no idea on that.
is there any solution or concept on doing this stuff?
very appreciate for your help
henry
|
|
|
|
|
I found a very nice mail server / client written entirely in C# (for .net sp2) with complete and well documented source code.
Has every component that goes into a complete mail server and client applications including MIME attachment handling, DNS, FTP, ICMP etc etc all broken separately for easy usage in other applications. The author states it's freeware.
I found it here originally:
http://www.c-sharpcorner.com/Code/2002/Nov/SMTPPOP3MailServer.asp[^]
But the most up to date version is on the author's site here:
http://www.lumisoft.ee/lsWWW/ENG/Products/Mail_Server/mail_index_eng.aspx?type=info[^]
Someone should convince them to post it to CodeProject, it's definitely worthy and illustrates many different useful concepts beyond the value of the code itself.
|
|
|
|
|
I've been using the Lumisoft mail server for over 6 months in a production environment using SqlServer2K as the mail store. It has been rock solid and is very simple to configure - highly recommended!
Jimmy
|
|
|
|
|
Actually since I posted this, I found several problems with it related to emails with attachments and it became unworkable in our business environment.
Everything was there and in general it worked fine at the time. It just needed to be more "fleshed out" to handle the variety of attachments, html email and globally used date formats correctly. (there was something else but I can't recall exactly what but it was something that would be minor for most but was a major problem for us with the business app I wanted to use it in)
I was going to extend it but ran out of time and had to opt for a commercial component instead (Chilkat).
I still think it's a very nicely written app and a good example of what you can do in C# with a real world application.
I'm curious if you have had any problems with attachments or if they have updated it since March 2003?
------------
Tomorrow is the same day as today was yesterday.
|
|
|
|