SFML community forums
Bindings - other languages => DotNet => Topic started by: felipehenrique on September 02, 2009, 10:14:04 pm
-
Hello.
I am beginner in the SFML and have a question.
How to integrate SFML with windows forms?
The part of the window will use the windows forms and the part of the game will use the SFML.
Thanks.
(sorry for the bad english, I am brazilian)
-
You can create a RenderWindow from the handle of an existing Form.
-
But how do this?
Could you give an example?
-
RenderWindow window = new RenderWindow(form.Handle);
-
Thanks for your help.
But the application crashes as soon as it starts, do not know what is wrong.
Here is the project in visual studio if you can analyze what is wrong, I will be eternally grateful.
And sorry for my ignorance, it is because I am a little beginner.
http://www.4shared.com/file/129959446/cc2af22/WindowsFormsApplication2.html
-
Its not crashing, its just that the main loop is blocking the windows form from monitoring events sent to it.. i have this same problem.
If someone knew of a way to force a winform to monitor events from within a loop that would should solve the problem... kinda
[EDIT!]
Ok so i figured out how to get it setup properly, and working with winforms also its better to start with an empty project when you do this instead of starting a winforms project.
heres the code i have:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace SFML_Application
{
class Window : Form
{
public Window()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// Window
//
this.ClientSize = new System.Drawing.Size(784, 562);
this.Name = "Window";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SFML Application";
this.ResumeLayout(false);
}
}
class SFMLApp
{
static void Main(string[] args)
{
Window Wnd = new Window();
SFML.Graphics.RenderWindow Scene = new SFML.Graphics.RenderWindow(Wnd.Handle);
SFML.Graphics.Shape Rect = SFML.Graphics.Shape.Rectangle(new SFML.Graphics.Vector2(0, 0),
new SFML.Graphics.Vector2(200, 100),
new SFML.Graphics.Color(255, 40, 40));
Wnd.Show();
while (Wnd.Created)
{
Application.DoEvents();
Scene.Clear();
Scene.Draw(Rect);
Scene.Display();
}
}
}
}
If you want to edit your winform, right click on the class that inherits from Form (Window i think) and select view designer.
There.
PS: it was Application.DoEvents( ) that allowed me to monitor events inside a loop.
-
If you work with WinForms then you should let it control the main execution flow, and insert your SFML stuff at the proper locations.
This topic gives a good solution:
http://www.sfml-dev.org/forum/viewtopic.php?p=10720#10720