Sign in to follow this  

Directx form controls

This topic is 4050 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
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

This topic is 4050 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this