Jump to content
  • Advertisement
Sign in to follow this  
Archenon

Directx form controls

This topic is 4270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hy i'm searching the internet for some time now and i ahvn't found what i needed. I'm a C# programer and heres my problem. I have a windows form and i want to write my own Direct X Button class. I derive the class from the System.Windows.Forms.Button class so i have all the propeties of a normal button. I override the OnPaint function so i can draw a texture with a sprite. When i draw on the main form everythings working ok. But there is a black box where the buttons image should be. I've checked the textures they are ok. class DXButton:System.Windows.Forms.Button { public Device device; public Texture[] texture = new Texture[2]; public Sprite sprite; public bool Pressed = false; public DXButton(int x, int y, int width, int height,string NormalImagePath,string PressedImagePath) { this.Location = new System.Drawing.Point(x, y); this.Size = new System.Drawing.Size(width, height); CreateFlags cflags; Caps devcaps = Manager.GetDeviceCaps(0, DeviceType.Hardware); if (devcaps.DeviceCaps.SupportsHardwareTransformAndLight) { cflags = CreateFlags.HardwareVertexProcessing; if (devcaps.DeviceCaps.SupportsPureDevice) { cflags |= CreateFlags.PureDevice; } } else{cflags = CreateFlags.SoftwareVertexProcessing;} PresentParameters param = new PresentParameters(); param.Windowed = true; param.SwapEffect = SwapEffect.Discard; device = new Device(0, DeviceType.Hardware, this, cflags, param); sprite = new Sprite(device); texture[0] = TextureLoader.FromFile(device, NormalImagePath); texture[1] = TextureLoader.FromFile(device, PressedImagePath); } protected override void OnPaint(System.Windows.Forms.PaintEventArgs pevent) { device.Clear(ClearFlags.Target, Color.White, 1f, 0); device.BeginScene(); sprite.Begin(SpriteFlags.Billboard); sprite.Draw2D(texture[0], Rectangle.Empty, Rectangle.Empty, this.Location, Color.White); sprite.End(); device.EndScene(); device.Present(); } } Hope you can help me

Share this post


Link to post
Share on other sites
Advertisement
First, I'd like to say this looks like a very bad idea. If you don't know why you're creating a device per button, then you probably don't mean to be doing this at all. Even when this works, I don't see this as ever being practical. [headshake]

Second, as a way of moving forward, have you tried removing the Sprite::Begin, Sprite::Draw and Sprite::End calls? Do you get a rectangle in the color you clear to (white in that code) or is it still black?

What you'd want to find out is if it's working and drawing black, or if it isn't drawing at all.

Hope this helps.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I already checked that and its not drawing at all. About devices fore very buton. Yesterday i tried passing the forms device to the constructor and wasn't working either and i saw a project with movies over panels where hor every panel it was a different device. And i just tried it .. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!