Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Render SMFL WIndows into Panel or something like this  (Read 6957 times)

0 Members and 1 Guest are viewing this topic.

sashadgt

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Render SMFL WIndows into Panel or something like this
« on: August 21, 2013, 12:04:25 am »
Hello i'm new here and the past few days i started working on small project using sfml 2.1 and c#.
The problem that i have is that i can't render a SFML window into a Panel, i have looked at forum and i have found some examples that didnt work for me, does someone have an example of that?
Thanks.

PS(I tried doing the same thing using Forms and making the RenderForm  MDIChild,it works but the scrollbars that i put in there and anchored them don't autoresize anymore)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Render SMFL WIndows into Panel or something like this
« Reply #1 on: August 21, 2013, 12:45:54 am »
I believe I posted a complete working example of this here.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

sashadgt

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Render SMFL WIndows into Panel or something like this
« Reply #2 on: August 21, 2013, 05:41:57 pm »
Yes i have seen this example, but what i need is the ability to use form builder with sfml, the same funcionality that panel has but with sfml in it. Right now i'm trrying to create a UserControl using the code that you have posted there without having to rely on form.
I dont know if i'm explaning myself well but what  ineed is
A container class with sfml inside that i does everything by itself and i can simply drag n drop to a form
Thanks.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Render SMFL WIndows into Panel or something like this
« Reply #3 on: August 21, 2013, 05:54:56 pm »
Yes i have seen this example, but what i need is the ability to use form builder with sfml, the same funcionality that panel has but with sfml in it. Right now i'm trrying to create a UserControl using the code that you have posted there without having to rely on form.
I dont know if i'm explaning myself well but what  ineed is
A container class with sfml inside that i does everything by itself and i can simply drag n drop to a form
Thanks.

So your trying to make your own user control that you can drag and drop onto the form in design mode? Something along these lines should help you out.

  • Add a new User Control file to your project
  • In the contructor create the SFML RenderWindow with this.Handle
  • Override the OnPaint and OnPaintBackground in that user control
  • Do your SFML drawing in OnPaint
  • Compile application
  • Drag user control from custom components to your form

Something like this should work.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

sashadgt

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Render SMFL WIndows into Panel or something like this
« Reply #4 on: August 21, 2013, 06:26:03 pm »
Yes i have tried that and it throws me a null pointer exepcion at sfml related events
here is the code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SFML.Graphics;
using SFML.Window;

namespace USERCTEST
{
    public partial class UserControl1 : UserControl
    {
        public SFML.Graphics.RenderWindow renderwindow;
        public UserControl1()
        {
            InitializeComponent();
            SFML.Graphics.RenderWindow renderwindow = new SFML.Graphics.RenderWindow(this.Handle);
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            System.Windows.Forms.Application.DoEvents();
            renderwindow.DispatchEvents();
            renderwindow.Clear(SFML.Graphics.Color.Green);
            renderwindow.Display();
        }
        protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
        {
           
        }
    }
}

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Render SMFL WIndows into Panel or something like this
« Reply #5 on: August 21, 2013, 06:40:03 pm »
This is where you need to use your debugger. When you redeclare a class variable inside a method the method variable will be destroyed at the end of the method.

Change

SFML.Graphics.RenderWindow renderwindow = new SFML.Graphics.RenderWindow(this.Handle);

To

renderwindow = new SFML.Graphics.RenderWindow(this.Handle);
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

sashadgt

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Render SMFL WIndows into Panel or something like this
« Reply #6 on: August 21, 2013, 07:01:25 pm »
A big thanks to you  for fixing my very very stupid mistake, thats what a few months without programming can do xD