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

Author Topic: sfml.net compiles but doesn't let me use it in a user control  (Read 6037 times)

0 Members and 1 Guest are viewing this topic.

Shadowblitz16

  • Newbie
  • *
  • Posts: 13
    • View Profile
does anybody know why my project compiles but when I try to add my SFMLCanvas to my form it throws an error?

I have don't the following..
-added sfmlnet-audio-2 to references
-added sfmlnet-graphics-2 to references
-added sfmlnet-system-2 to references
-added sfmlnet-window-2 to references

-added all extlibs to root of project and set output directory to "Copy id newer"

and this is my code..
Code: [Select]
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 Zelda_2_Editor
{
    public partial class SFMLCanvas : UserControl
    {
        public RenderWindow renderwindow;
        public SFMLCanvas()
        {
            InitializeComponent();
            renderwindow = new RenderWindow(this.Handle);
        }

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

        }
    }
}

here is what it looks like when it happens


can somebody tell me whats wrong and how to fix it?

Gleade

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: sfml.net compiles but doesn't let me use it in a user control
« Reply #1 on: August 01, 2017, 12:56:11 am »
You need the CSFML binaries to be in the same directory as the .NET libraries.

Shadowblitz16

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: sfml.net compiles but doesn't let me use it in a user control
« Reply #2 on: August 01, 2017, 07:03:54 am »
thats not much help since I have all the dlls copied to the bin/Debug folder

here is the project if you don't believe me.
https://drive.google.com/open?id=0B16wNFPwi_2kQnpINFIwVnpjWmc
« Last Edit: August 01, 2017, 07:07:29 am by Shadowblitz16 »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sfml.net compiles but doesn't let me use it in a user control
« Reply #3 on: August 01, 2017, 02:06:02 pm »
I don't know if it's the same for .NET as for C++.
Do .NET's debug DLLs also have "-d"?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Shadowblitz16

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: sfml.net compiles but doesn't let me use it in a user control
« Reply #4 on: August 02, 2017, 03:53:37 am »
no but I found what the issue is partially.
you can't use external libraries like smfl.net during design time.

I fixed it with the sfmlCanvas by doing..
Code: [Select]
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 Zelda_2_Editor
{
    public partial class SFMLCanvas : UserControl
    {
        public RenderWindow renderwindow;
        //public SFML.Graphics.Color DrawColor;
        public SFMLCanvas()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            if (!DesignMode)
            {
                renderwindow = new RenderWindow(this.Handle);
                //DrawColor = SFML.Graphics.Color.Black;
            }
            base.OnLoad(e);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (!DesignMode)
            {
                Application.DoEvents();
                renderwindow.DispatchEvents();
                renderwindow.Clear(SFML.Graphics.Color.Black);
                renderwindow.Display();
            }
        }
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            base.OnPaintBackground(pevent);
        }
    }
}
sadly it still crashes when I add that userControl to another userControl and then add that in the designer.

for example this code doesn't work because it has a sfmlCanvas in it.
Code: [Select]
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;

namespace Zelda_2_Editor.Controls
{
    public partial class SFMLButton : UserControl
    {
        public SFMLButton()
        {
            InitializeComponent();
            //Text = "";
        }

        protected override void OnLoad(EventArgs e)
        {
            if (!DesignMode)
            {
                //sfmlCanvas.DrawColor = new SFML.Graphics.Color(BackColor.R, BackColor.G, BackColor.B);
                sfmlCanvas.Enabled = false;
            }
            base.OnLoad(e);
        }
    }
}

Gleade

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: sfml.net compiles but doesn't let me use it in a user control
« Reply #5 on: August 03, 2017, 01:19:48 am »
I had this exact same issue & came to the same conclusion you did. Sadly this is the case.

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: sfml.net compiles but doesn't let me use it in a user control
« Reply #6 on: August 03, 2017, 07:49:07 pm »
You might try taking a look at this workaround and see how it works for you: https://stackoverflow.com/a/6036800

Shadowblitz16

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: sfml.net compiles but doesn't let me use it in a user control
« Reply #7 on: February 20, 2018, 02:20:39 am »
I shouldn't have to add sfml to my path variables

this is obviously a conflict between sfml and winforms if you would like to link a sfml render window control I would be glad to try it.

 

anything