JFormDesigner Runtime Library Doesn't Load Custom Code - jform-designer

I've been using JFormDesigner with the runtime library to create dialogs directly from the .jfd files at runtime (I can't change this; not my decision). My problem is that the runtime library doesn't seem to preserve any custom code generation listed in the .jfd file. For example, if I have a simple panel, with the background set to red, and a post-initialization command to set the background to green, the runtime library will yield a red background, while directly loading the generated .java file will properly set the background to green.
Here's a code sample of what I'm doing:
public class EntryPoint
{
public static void main( String[] args )
{
// Load .jfd file. Shows red background (incorrect).
String form = "testProject/entry/TestDialog.jfd";
new EntryPoint(form);
// Load .java file. Shows green background (correct).
JFrame frame = new JFrame();
TestDialog test = new TestDialog( frame );
test.setVisible( true );
}
EntryPoint( String form )
{
try
{
// Example loading
// see http://www.formdev.com/jformdesigner/doc/runtime-library/
FormModel formModel = FormLoader.load( form );
FormCreator formCreator = new FormCreator(formModel);
formCreator.setTarget(this);
JDialog dialog = formCreator.createDialog(null);
dialog.setModal(true);
dialog.pack();
dialog.show();
}
catch( Exception e )
{
e.printStackTrace();
}
}
}
I took a quick look at the documentation, but to no avail. I have an e-mail sent to JFD's support team, and will update the question if I get any response. I'm looking through the runtime library code now (it's open source), but was curious if anyone had any info on it before I go too far down the rabbit hole. Thanks.

Support replied; feature not currently supported (as of version 5.2).

Related

WPF native windows 10 toasts

Using .NET WPF and Windows 10, is there a way to push a local toast notification onto the action center using c#? I've only seen people making custom dialogs for that but there must be a way to do it through the os.
You can use a NotifyIcon from System.Windows.Forms namespace like this:
class Test
{
private readonly NotifyIcon _notifyIcon;
public Test()
{
_notifyIcon = new NotifyIcon();
// Extracts your app's icon and uses it as notify icon
_notifyIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
// Hides the icon when the notification is closed
_notifyIcon.BalloonTipClosed += (s, e) => _notifyIcon.Visible = false;
}
public void ShowNotification()
{
_notifyIcon.Visible = true;
// Shows a notification with specified message and title
_notifyIcon.ShowBalloonTip(3000, "Title", "Message", ToolTipIcon.Info);
}
}
This should work since .NET Framework 1.1. Refer to this MSDN page for parameters of ShowBalloonTip.
As I found out, the first parameter of ShowBalloonTip (in my example that would be 3000 milliseconds) is generously ignored. Comments are appreciated ;)
I know this is an old post but I thought this might help someone that stumbles on this as I did when attempting to get Toast Notifications to work on Win 10.
This seems to be good outline to follow -
Send a local toast notification from desktop C# apps
I used that link along with this great blog post- Pop a Toast Notification in WPF using Win 10 APIs
to get my WPF app working on Win10. This is a much better solution vs the "old school" notify icon because you can add buttons to complete specific actions within your toasts even after the notification has entered the action center.
Note- the first link mentions "If you are using WiX" but it's really a requirement. You must create and install your Wix setup project before you Toasts will work. As the appUserModelId for your app needs to be registered first. The second link does not mention this unless you read my comments within it.
TIP- Once your app is installed you can verify the AppUserModelId by running this command on the run line shell:appsfolder . Make sure you are in the details view, next click View , Choose Details and ensure AppUserModeId is checked. Compare your AppUserModelId against other installed apps.
Here's a snipit of code that I used. One thing two note here, I did not install the "Notifications library" mentioned in step 7 of the first link because I prefer to use the raw XML.
private const String APP_ID = "YourCompanyName.YourAppName";
public static void CreateToast()
{
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(
ToastTemplateType.ToastImageAndText02);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("This is my title!!!!!!!!!!"));
stringElements[1].AppendChild(toastXml.CreateTextNode("This is my message!!!!!!!!!!!!"));
// Specify the absolute path to an image
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + #"\Your Path To File\Your Image Name.png";
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
imageElements[0].Attributes.GetNamedItem("src").NodeValue = filePath;
// Change default audio if desired - ref - https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-audio
XmlElement audio = toastXml.CreateElement("audio");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Reminder");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.IM");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Mail"); // sounds like default
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Call7");
audio.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Call2");
//audio.SetAttribute("loop", "false");
// Add the audio element
toastXml.DocumentElement.AppendChild(audio);
XmlElement actions = toastXml.CreateElement("actions");
toastXml.DocumentElement.AppendChild(actions);
// Create a simple button to display on the toast
XmlElement action = toastXml.CreateElement("action");
actions.AppendChild(action);
action.SetAttribute("content", "Show details");
action.SetAttribute("arguments", "viewdetails");
// Create the toast
ToastNotification toast = new ToastNotification(toastXml);
// Show the toast. Be sure to specify the AppUserModelId
// on your application's shortcut!
ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
}
UPDATE
This seems to be working fine on windows 10
https://msdn.microsoft.com/library/windows/apps/windows.ui.notifications.toastnotificationmanager.aspx
you will need to add these nugets
Install-Package WindowsAPICodePack-Core
Install-Package WindowsAPICodePack-Shell
Add reference to:
C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd
And
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
And use the following code:
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
for (int i = 0; i < stringElements.Length; i++)
{
stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
}
// Specify the absolute path to an image
string imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png");
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier("Toast Sample").Show(toast);
The original code can be found here: https://www.michaelcrump.net/pop-toast-notification-in-wpf/
I managed to gain access to the working API for windows 8 and 10 by referencing
Windows.winmd:
C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral
This exposes Windows.UI.Notifications.
You can have a look at this post for creating a COM server that is needed in order to have notifications persisted in the AC with Win32 apps https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/10/16/quickstart-handling-toast-activations-from-win32-apps-in-windows-10/.
A working sample can be found at https://github.com/WindowsNotifications/desktop-toasts

Windows Forms OpenFileDialog and LibVLC plugins dll entry point error

I'm using libvlc library. And it works well when I play the video file, that I have chosen in openFileDialog previously. But my goal is streaming video from webcam and previewing it.
I made libvlc show webcam video on the screen, but when i commented out the openFileDialog.Show() line (that I don't need anymore), "Entry point couldn't be found in the library" error dialogs started poping out for every libvlc plugin (that is basicaly a .dll file).
private void btPlay_Click(object sender, EventArgs e)
{
/*
if (openFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
* */
CleanUp();
string pluginPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins");
string[] args = new string[]{
"--no-qt-error-dialogs",
"--ignore-config",
"--quiet",
"--plugin-path=" + pluginPath
};
//LibVlc initialization, that is where ERORR OCCURES
vlcInst = new VlcInstance(args);
/* Input media settings */
//VlcMedia media = new VlcMedia(vlcInst, openFileDialog1.FileName);
VlcMedia media = new VlcMedia(vlcInst, "dshow://");
LibVlc.libvlc_media_add_option(media.handle, "dshow-vdev=USB2.0 UVC VGA WebCam");
LibVlc.libvlc_media_add_option(media.handle, "dshow-adev=none");
/* Output media settings */
string[] outputOptions = new string[] {
"sout=#duplicate{",
"dst=",
"display",
",",
"dst=",
"'",
"transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100}",
":http{mux=ffmpeg{mux=flv},dst=:666/}",
"'",
"}"
};
LibVlc.libvlc_media_add_option(media.handle, String.Concat(outputOptions));
streamer = new VlcStreamer(media);
media.Dispose();
streamer.Drawable = mediaPanel.Handle;
streamer.Play();
}
private void CleanUp()
{
if (streamer != null)
{
streamer.Stop();
streamer.Dispose();
}
}
I can't see any relations between OpenFileDialog and libvlc plugins.
What can cause such a problem?
EDITED:
After I skip all error dialogs, program continues working.
When I was using VLC player, it made duplicates of the plugins in "plugin" folder. In my app I used those plugins and was getting errors. After I downloaded and unpacked new instance of the player, I discovered that there were no duplicates of the plugins, so I made a conclusion that the player makes copies of plugins when you launch it first time (didn't test it).
When I replaced my plugin folder with new one, all the errors were gone.

How to call a method from WindowsForms in Monogame?

Hi im currently working on a project. My main form is a form and whenever i click on a button the monogame program starts. This works.
Now i made a method in the main form and i want to pass the bool to the monogame form.
Main Form method: (if checkbox is checked monogame should draw a skyline)
public bool skyCheck()
{
if (checkBox1.Checked == true)
{
sky = true;
}
else
{
sky = false;
}
return sky;
Monogame check:
if (skyCheck() == true)
{
DrawSky();
}
This gives me the name 'skyCheck' does not exist in the current context.
I made a Control that embeds a monogame into a form so that a seperate program doesn't have to be run. It isn't the normal embedded monogame you see that only gives you a graphics device and no update or game methods. it's an actual monogame embeded.
This is not the source of your problem but it could help fix it along with make your program better.
Here is the source and some brief documentation is contained in the Readme on how to use it
Pass a reference of the form to the constructor of Game1:
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
//Change the Form1 to the name of the form class.
Form1 form;
//...
public Game1(Form1 form)
{
this.form = form;
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
//...
// I will assume the DrawSky() should be called in Draw.
protected override void Draw(GameTime gameTime)
{
//...
if (form.skyCheck()) // the "== true" is redundant.
{
DrawSky();
}
//...
}
}
The following code would normally be in Program.cs, but as a Window Forms application, this code would be in the form that launches the game:
game = new Game1(this); // where "this" refers to the current form
game.Run();
Please note the caveats to mixing Windows forms and MonoGame:
The form's message pump and the Game run in the same thread. Any stall on the form will cause the game to lag.
There will be a performance penalty.
Make sure the game shuts down properly before the form is unloaded to ensure the resources are cleaned up properly.
It is is possible to start another thread for the game to run in(thus bypassing the first two caveats), but, all communication between the two threads must be thread safe. Thread safety is guaranteed for a Boolean assignments, as well as Integer assignments (=< 32 bits for 32 bit processes, and =< 64 for 64-bit processes).
Exit coordination in both threads is required.

How Do I Add Background Thread To Silverlight Custom Control?

I'm building a custom control for Windows Phone 7+ that can do augmented reality image processing. The control works wonderfully in practice (when I run the app), but because I have the image processing running on a separate thread, it breaks when I try to open the page in Blend or the Visual Studio designer.
Here's an example of the thread I'm trying to run (basically taken from http://msdn.microsoft.com/en-us/library/hh202982(v=vs.92).aspx) :
public override void OnApplyTemplate()
{
// assigning template stuff, initializing my camera
_myManualResetEvent = new ManualResetEvent(true);
_myCameraProcessingThread = new System.Threading.Thread(ProcessingMethod);
_myCameraProcessingThread.Start();
}
void ProcessingMethod()
{
int[] myBuffer = new int[640 * 480];
while(_someCondition)
{
_myManualResetEvent.WaitOne();
_myCamera.GetPreviewBufferArgb32(myBuffer);
// do my processing stuff
_myManualResetEvent.Set();
}
}
This breaks the ever-loving heck out of Blend. Would love to know why.
It looks like you are doing a lot of run-time stuff in the OnApplyTemplate method.
This will get called when Blend or Visual Studio instantiates the design view of your control.
You should either check to see if you are in design mode using the DesignMode:
if (!DesignMode)
{
_myManualResetEvent = new ManualResetEvent(true);
_myCameraProcessingThread = new System.Threading.Thread(ProcessingMethod);
_myCameraProcessingThread.Start();
}
or move this code into a method/event handler that only gets called when the application actually runs.

What is the simplest way to display (and change) an image resource on a WPF dialog (using C++/CLI)?

I have a C++/CLI GUI application and I want to display an image as a visual aid for the user to see what step in a procedure they're at. This image will need to be changed each time the user selects the new step.
Currently I'm using a picture box and have an image loaded from the disk at run time. So there are a few things I need to know here:
Is a picture box the best thing to use for this purpose or is there another control that would better suit?
How do embed the images in the executable and load them from there instead of a file that exists on disk.
How do I load a new image (I'm guessing that this will be fairly obvois if I can crack point 2)?
I've seen a few answers which relate to C# but I've not seen anything which looks like it translates to doing things in a C++/CLI app. Any suggestions would be very welcome.
Well it may not be the best solution, but the following works.
Create a new Windows Forms Application
Add these libraries to your linker settings (Project Proerties -> Link -> Input -> Additional Dependencies):
User32.lib Gdi32.lib
Add these headers:
#include <windows.h>
#include "resource.h"
Add these namespaces:
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
Add a pair of bitmaps to your resources and call them IDB_BITMAP1 and IDB_BITMAP2.
Add a picture box called m_pictureBox1.
Add a button and double-click the button to add an on-click handler:
System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
// Remove any previously stored images
if(m_pictureBox1->Image != nullptr)
{
delete m_pictureBox1->Image;
}
// Pick a new bitmap
static int resource = IDB_BITMAP1;
if( resource == IDB_BITMAP2)
{
resource = IDB_BITMAP1;
}
else
{
resource = IDB_BITMAP2;
}
// Get the primary module
Module^ mod = Assembly::GetExecutingAssembly()->GetModules()[0];
// Get the instance handle
IntPtr hinst = Marshal::GetHINSTANCE(mod);
// Get the bitmap as unmanaged
HANDLE hbi = LoadImage((HINSTANCE) hinst.ToPointer(),MAKEINTRESOURCE(resource),IMAGE_BITMAP,0,0,LR_DEFAULTCOLOR);
// import the unmanaged bitmap into the managed side
Bitmap^ bi = Bitmap::FromHbitmap(IntPtr(hbi));
// insert the bitmap into the picture box
m_pictureBox1->Image = bi;
// Free up the unmanaged bitmap
DeleteObject(hbi);
// Free up the instance and module
delete hinst;
delete mod;
}
..et voila the bitmaps are stored neatly in you app and each time you click the button the images will swap.

Resources