Hi I'm using SFML.net 2.1. I'm trying to get a SFML window inside a picturebox but I am having no luck.
public partial class Form1
: Form
{ private RenderWindow mapWindow
; private bool running
= true; public Form1
() { InitializeComponent
(); } private void Draw
() { Application
.DoEvents(); mapWindow
.Clear(new SFML
.Graphics.Color(101,
156,
239)); mapWindow
.Display(); pictureBox1
.Refresh(); } private void Form1_FormClosed
(object sender, FormClosedEventArgs e
) { running
= false; } private void pictureBox1_LoadCompleted
(object sender, AsyncCompletedEventArgs e
) { mapWindow
= new RenderWindow
(this.pictureBox1.Handle); while (running
) Draw
(); } }
I did manage to get a SFML RenderWindow embedded inside the form.
public partial class Form1
: Form
{ private RenderWindow mapWindow
; private bool running
= true; public Form1
() { InitializeComponent
(); } private void Draw
() { Application
.DoEvents(); mapWindow
.Clear(new SFML
.Graphics.Color(101,
156,
239)); mapWindow
.Display(); } private void Form1_FormClosed
(object sender, FormClosedEventArgs e
) { running
= false; } private void Form1_Load
(object sender, EventArgs e
) { mapWindow
= new RenderWindow
(this.Handle); while (running
) Draw
(); } } Thanks
Here is a sample that works. Note you do not need your own control as I did in this example, but doing it this way prevents SFML and the control fighting to paint the same area. I commented the code so it should be self explanatory. I also recommend that you add SFML to a form from outside the form's load events as I did here.
class Example
{ static void Main
() { // initialize the form System.Windows.Forms.Form form
= new System.Windows.Forms.Form(); // create our form form
.Size = new System.Drawing.Size(600,
600); // set form size to 600 width & 600 height form
.Show(); // show our form DrawingSurface rendersurface
= new DrawingSurface
(); // our control for SFML to draw on rendersurface
.Size = new System.Drawing.Size(400,
400); // set our SFML surface control size to be 500 width & 500 height form
.Controls.Add(rendersurface
); // add the SFML surface control to our form rendersurface
.Location = new System.Drawing.Point(100,
100); // center our control on the form // initialize sfml SFML
.Graphics.RenderWindow renderwindow
= new SFML
.Graphics.RenderWindow(rendersurface
.Handle); // creates our SFML RenderWindow on our surface control // drawing loop while (form
.Visible) // loop while the window is open { System.Windows.Forms.Application.DoEvents(); // handle form events renderwindow
.DispatchEvents(); // handle SFML events - NOTE this is still required when SFML is hosted in another window renderwindow
.Clear(SFML
.Graphics.Color.Yellow); // clear our SFML RenderWindow renderwindow
.Display(); // display what SFML has drawn to the screen } } } public class DrawingSurface
: System.Windows.Forms.Control { protected override void OnPaint
(System.Windows.Forms.PaintEventArgs e
) { // don't call base.OnPaint(e) to prevent forground painting // base.OnPaint(e); } protected override void OnPaintBackground
(System.Windows.Forms.PaintEventArgs pevent
) { // don't call base.OnPaintBackground(e) to prevent background painting //base.OnPaintBackground(pevent); } }