I wanted to draw a 5 pointed star in C# and here is how I finally did it. I leave it as an exercise (some hints are given in the code) to work out how I did this. It was fun to do (but a bit hard, my trig is getting worned out :) ) but if you want to ask questions please do. For the installation of the code please refer to this snippet: [url]http://www.daniweb.com/software-development/csharp/code/359360[/url]

Member Avatar
Member Avatar
+1 forum 13

Hello everyone. I would like to know if it is possible to double buffer a .png image using GDI+ Can anyone help me? Below is the code I used to display a png image with alpha transparency, however, I do not know how to double buffer it! Please help. DrawPng (HDC hdc, HINSTANCE hinstance, HWND hwnd, int curbitmapvalue, int posX, int posY) { HRSRC hRsrc; hRsrc = FindResource(hinstance, MAKEINTRESOURCE(curbitmapvalue), "PNG"); HGLOBAL hImage; hImage = LoadResource(hinstance, hRsrc); LPVOID pImage; pImage = LockResource(hImage); HGLOBAL hBlock; IStream *pStream=NULL; int size= SizeofResource(hinstance, hRsrc); hBlock=GlobalAlloc(GHND, size); LPVOID pBlock; pBlock = GlobalLock(hBlock); memmove(pBlock,pImage, size); CreateStreamOnHGlobal(hBlock, FALSE, …

Member Avatar
Member Avatar
+0 forum 1

When you want to draw something on a form you need a Graphics object. But a Graphics constructor isn’t public and if that is not enough the Graphics class is also sealed! This means you can’t create a Graphics object via the new keyword nor can you derive from the Graphics class. One way to get a Graphics object is through a Paint event handler of a Form via the PaintEventArgs class. OK now you can use an array of Points, pass it with a Pen object to DrawLines and it draws your function! This is not what I want …

Member Avatar
Member Avatar
+0 forum 15

i have a png file, or gif if that makes any difference which i am redrawing using GDI+. [ICODE] Bitmap b6 = new Bitmap(525, 525, System.Drawing.Imaging.PixelFormat.Format32bppArgb); b6.SetResolution(300, 300); using (Graphics grPhoto = Graphics.FromImage(b6)) { grPhoto.CompositingMode = CompositingMode.SourceCopy; grPhoto.SmoothingMode = SmoothingMode.HighQuality; grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic; grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality; grPhoto.CompositingQuality = CompositingQuality.HighQuality; //now do the crop grPhoto.DrawImage(loadedImage1, imageBounds1.Location.X, imageBounds1.Location.Y); }[/ICODE] The original image is transparent, but when i re draw, the background is black.. any fix for this? The image has transparency inside the picturebox initally.

Member Avatar
+0 forum 0

This is not about a DataGridView or something else, it is just about drawing a simple grid in a form window. Googled a bit but found not much of my liking. A Grid as a BitMap in a PictureBox? Come on! Must have been some of those GUI guys I guess. I find it easier to draw in a Form or a Panel in a Form, so I have total control over where to draw a chess piece or a Sudoku number or whatever. Or I could draw a graph with a grid; think it’s harder to do that with …

Member Avatar
Member Avatar
+0 forum 6

hi, actually i wanted to draw two cubes programmatically in C# with only top,front and right portions visible.the top and right portion will have the same dimensions but depending on the parameter width provided by the user,the front portion will increase along the horizontal axis.One cube will increase along the positive x axis and other one will increase towards the negative x axis i.e one will progress towards the left side and other will progress towards the right side. Can you please provide the C# code for this asap.Thanks in advance

Member Avatar
Member Avatar
-1 forum 21

So i'm creating a form, on the form is a panel (panel1) which holds all data, pictures etc... This is then to be made into a bmp for professional printing (ie 300dpi). A4 @ 300dpi = 2480 x 3508; i am able to create the image at the panel's height and width. and i have also recently got it to create a document 2480x3508, but the panel is being shown in the top left corner with a whole lot of white space.. what am i doing wrong?.. is there a [I]Better [/I]way to create this image, as quality is a …

Member Avatar
Member Avatar
+0 forum 4

hi there, i'm creating an app in C# which allows users to select an image by double clicking the "pictureBox1", from there it selects the image, creates a new Graphics object and passes the Bitmap to it. Once the picture has been loaded the user should be able to move the picture around using the mouseDown, mouseMove, mouseUp events. I have got the image to load correctly, but it does not move.. if i alter the code, it moves, but the user is unable to select a new image(by double clicking), and it will just load a box with a …

Member Avatar
Member Avatar
+0 forum 5

I want to draw a editable TextBox on top of picture box and the user is allowed to enter text into this box.After entering text the text box should disappear and the text entered should be painted to the picture in the picture box.Please help me on this,I'am doing this in c#.

Member Avatar
Member Avatar
+0 forum 6

when uploading an image to the website i get the following error message: [CODE] Server Error in '/' Application. A generic error occurred in GDI+. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: …

Member Avatar
Member Avatar
+0 forum 1

Hello All, I am working on GDI+ programming and created a windows form to draw lines by mouse. Here is my sample code. [CODE] using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace SampleApplication { public partial class frmTest : Form { SolidBrush brush; bool isMouseDown = false; Pen pen; Point startPos; Point curPos; public frmTest() { InitializeComponent(); brush = new SolidBrush(Color.FromArgb(100, Color.Black)); pen = new Pen(brush, 20); // A big size semi transparent pen } private void frmTest_MouseDown(object sender, MouseEventArgs e) { isMouseDown = true; startPos.X = e.X; startPos.Y = e.Y; …

Member Avatar
Member Avatar
+0 forum 1

Hello, I want to create a set of Brush tools as we found in Ms Paint like Crayon, Marker, natural pencil, oil brush and water color brush. How I can achieve this using GDI+? Please help me out on this. Regards, Jayant Paliwal

Member Avatar
+0 forum 0

hello, i am using the Graphics.DrawLine method in C# and this is fine for thin lines but for thick lines it draws really badly. i have sample code to reproduce the problem below. just create a new c# forms application and add a picture box to the form. make the picture box the same size as the form and add empty MouseUp, MouseDown and MouseMove event handlers. then add this to form1.cs: [CODE] public partial class Form1 : Form { //var Pen myPen; bool bMouseDown = false; Point prevPoint; Graphics g; //ctor public Form1() { InitializeComponent(); } private void pictureBox1_MouseUp(object …

Member Avatar
Member Avatar
+0 forum 5

I mostly use Console or Forms applications in VS for my projects. Did anyone among you ever use an Empty Project when starting a new one? Well, it is as clean as you can get with Visual Studio! The world is at your feet! I use it mainly to test some drawing methods from the Graphics class. To get a feeling of it, let’s start a new empty project. I called mine “Draw” and I right clicked it to get the properties window and set the [B]Output type:[/B] to [B]Windows Application[/B], to avoid that a console window opens also. Because …

Member Avatar
Member Avatar
+2 forum 2

Ever wanted to know how to implement running lights? well here is your chance to find out. Open a new Forms application enlarge the Form a bit and drop a Panel and a Timer on it. Add the class ChasingLights to the solution, see code. Implement a form Load, panel Paint and Timer Tick event. See code. I have included the result you should get(without the "lights" running;) ) Also added a few fancy tricks you can do with strings. Have fun!

Member Avatar
Member Avatar
+5 forum 1

I needed a very simple multi-line label control for a project I was working on, It had very simple requirements. It needed to draw text in any font, in any color, on multiple lines with vertical and horizontal alignment control. So I hacked up this little class. Just as easy to use as a standard label control.

Member Avatar
+2 forum 0

What is the use of GDI+? Can I use it for creating custom controls to use in Vector Graphics program?

Member Avatar
Member Avatar
+0 forum 1

hi all i'm trying to draw an oval/ellipse over an existing square the problem is that the oval is drawn behind the rectangle how do i fix this? here is my form's code [code] using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Quoridor { public partial class Game : Form { public const int N = 7; GameNode[,] Mat = new GameNode[7,7]; public Game() { InitializeComponent(); for(int i=0;i<N;i++) for(int j=0;j<N;j++) { Mat[i, j] = new GameNode(); Mat[i, j].pictureBox = new PictureBox(); // Mat[i, j].pictureBox.BorderStyle = BorderStyle.Fixed3D; Mat[i, j].pictureBox.Location = new Point(10+i*50+i*10, …

Member Avatar
Member Avatar
+0 forum 4

How can i move the Rectangle on the form and animate it as it moves? If i want to move it for example to the right, i must increase it's X cordinate, right? I did it (++x) and drawed a new rectangle and overdrawed the old one with background color. Is it right? or maybe there is better idea? Is there any timer to slow down the animation process? Thnx in advance :)

Member Avatar
Member Avatar
+0 forum 6

Hi, I would like to write a program that enable user to draw geometric shapes like circles, triangles, rectangles and so on. I would like also to be able to drag and drop or resize a shape that was previously drawn. 1) I thought to draw the shapes inside a Panel. Does it seems reasonable ? 2) Say I drew several shapes. Then I want to resize the first drawn shape. How can I identify that the first shape was clicked ? Thanks !

Member Avatar
Member Avatar
+0 forum 11

Hi, I don't know C# very well, so I did^n't understand where the problem is. Program works without errors. But it doesn't do what I want, when I click on panel1 , not draws rectangle. Maybe, you can realise something wrong in the code. [CODE] using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace bezier_rotation { public partial class Form1 : Form { private List<double> ptList = new List<double>(); private BezierCurve bc = new BezierCurve(); OpenGLView ogl; public Form1() { InitializeComponent(); ogl = new OpenGLView(); ogl.Parent = panel1; ogl.Dock = DockStyle.Fill; ogl.Refresh(); …

Member Avatar
Member Avatar
+0 forum 1

Hi, I have a code where I have to use the region class in drawing. When I type using System.Drawing., the region class doesnt appear in the drop down list. I know this is a kinda silly doubt, but I need to include it in my project. Thanks prashanth

Member Avatar
Member Avatar
+0 forum 3

Hi, I have this following code for RGB to HSL conversion, but I do not know how to use it to display my image. Can someone help out [CODE]var_R = ( R / 255 ) //RGB from 0 to 255 var_G = ( G / 255 ) var_B = ( B / 255 ) var_Min = min( var_R, var_G, var_B ) //Min. value of RGB var_Max = max( var_R, var_G, var_B ) //Max. value of RGB del_Max = var_Max - var_Min //Delta RGB value L = ( var_Max + var_Min ) / 2 if ( del_Max == 0 ) //This …

Member Avatar
Member Avatar
+0 forum 2

Iv made conways game of life, but I want the user to be able to select a pre defined pattern or for them to be able to choose different shaped brushes then draw with that brush. Aswell, when I use the radio buttons to change the size, the program goes slow and stops working, does anyone know why that is? And, Iv tried to create an eraser type tool using brush color.empty, but it doesnt work, how can I create an eraser tool, or a button to completely clear what the user has drawn, everything Iv tried has not worked. …

Member Avatar
Member Avatar
+0 forum 3

hi all .. just want to ask if anyone have an idea how can i move image down throug keyboard cursors up an down .. i know that there is the keydown event and the keyup event but really i don't know how to write the code .. other qusetion how can i show images randomly with timer ? thanks

Member Avatar
Member Avatar
+0 forum 13

hi all iam new in this forum and i need some help in my assignment .. it's a c# game using graphics .. this game when start it should show a sheep then a chicken randomly then all graphics will move to the left .. there will be a dora girl which moving up and down ,, if she catch a sheep the score will increase by 10 else the score will decreas by 10 and the all over time is 90 sec .. any idea how i should start ??

Member Avatar
Member Avatar
+0 forum 6

hi, i have a graph and i wanna zoom somw particular area in it. Is there any zoom function available... thanx

Member Avatar
Member Avatar
+0 forum 3

Wanted to let two forms work together. One form would be the input form and the main form would consume this data. I managed to succeed with the help of a few of my friends here at daniweb., who helped me setup a static form. Just posted a bit of the most relevant code here, the rest of the project can be found in the attachments. I also like to mention a technique used here to attach a value to a selection of a name in a combobox.(Found it on MSDN) See the list of Planets. (Yes, throw a ball …

Member Avatar
Member Avatar
+1 forum 2

Ok I'm converting a program from Java to C# and currently stuck on a certain aspect of it. Ok I have; [code=Java]private Graphics g1; private Bitmap picture; picture = new Bitmap(x1, y1); g1 = Graphics.FromImage(picture); pbMand.Image = picture;[/code] pbMand is the name of my picture box, which I will use to display the image (not drawing directly to form, using PB). Then further on I have... [code=java] g1.setColor(Color.FromArgb(Convert.ToInt16(h), Convert.ToInt16(0.8f), Convert.ToInt16(b))); //djm test Color col = Color.getHSBColor(h, 0.8f, b);[/code] I can't find an equivilent form javas setColor to something in C#...It seems to lack anything colour related in g1's methods. And …

Member Avatar
Member Avatar
+0 forum 2

I have been working on a custom Hue Slider, when you drag the knob the color of it changes to its hue value. (ex 0 is red). I added a little gloss to the knob, I feel its not done, I Just don't have any Ideas as to how to give it finishing touches... any ideas people? I would like it to look a little more professional. image attached:

Member Avatar
Member Avatar
+1 forum 15

The End.