enter image description hereHere's the code:
#using < system.drawing.dll>
using namespace System;
using namespace System::Drawing;
protected:
virtual Void Form1::OnPaint(PaintEventArgs ^ pe) override
{
Graphics ^ g = pe->Graphics;
Image ^ image = Image::FromFile("SampleImage.jpg");
Form::ClientSize = image->Size;
g->DrawImage(image, 0, 0, image->Size.Width, image->Size.Height);
}
The error text is ""#using" requires C++/CLI mode".
adding pragma
adding /clr in tasks.json
One of the options:
Add #pragma managed on the top file line:
#pragma managed
#using < system.drawing.dll>
// ...
Add /clr to args in tasks.json
Related
How to Display Entry Control with PlaceHolder Text in MAUI.
I need to write a EntryHandler which would look like the below Image
(Last Name* is the placeholder text)
I have written a entry handler with out the border which is looking like below, the problem with this is as the user starts typing the placeholder text hides
public class BorderlessEntry : Entry
{
}
public App(AppShell page)
{
InitializeComponent();
Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(nameof(BorderlessEntry), (handler, view) =>
{
if (view is BorderlessEntry)
{
#if __ANDROID__
handler.PlatformView.SetBackgroundColor(Microsoft.Maui.Graphics.Colors.Transparent.ToAndroid());
handler.PlatformView.Hint = view.Placeholder;
#elif __IOS__
handler.PlatformView.BackgroundColor = Microsoft.Maui.Graphics.Colors.Transparent;
handler.PlatformView.Layer.BackgroundColor = Microsoft.Maui.Graphics.Colors.Transparent;
handler.PlatformView.BorderStyle = UIKit.UITextBorderStyle.None;
#endif
}
});
}
I have been able to achieve the same in Xamarin Forms using MaterialEntryRenderer but the same is not supported in .net Maui
Any help is appreciated!
The code below was working until around preview 11 of Maui. But with preview 13 I get a compiler error: 'EntryHandler' does not contain a definition for 'EntryMapper'.
A similar error is shown for PickerMapper.
The code has been copied from the official documentation.
#if ANDROID
using Microsoft.Maui.Controls.Compatibility.Platform.Android;
#endif
using Application = Microsoft.Maui.Controls.Application;
namespace myapp;
public partial class App : Application
{
public App(AuthenticationService authenticationService, SyncService syncService)
{
InitializeComponent();
// Remove underline from all pickers and entries in app
#if ANDROID
Microsoft.Maui.Handlers.PickerHandler.PickerMapper.AppendToMapping("NoUnderline", (h, v) =>
{
h.NativeView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
});
Microsoft.Maui.Handlers.EntryHandler.EntryMapper.AppendToMapping("NoUnderline", (h, v) =>
{
h.NativeView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
});
#endif
MainPage = new AppShell(authenticationService, syncService);
}
}
Anyone who sees the solution?
I have been searching high and low, but the consensus seems to be that the code is correct.
I think all the EntryMapper and PickerMapper, basically all {Control}Mapper got renamed to just Mapper.
Additionally, I see you have references to NativeView whenever you upgrade to preview 14, those will be renamed to PlatformView so you will have to rename those accordingly as well.
I would need a simple working example (using Gtkmm 3) of a ShortcutsWindow with just one ShortcutsShortcut that does not use a Gtk::Builder.
I have not been able to find such an example online. I am able to show window however shortcuts do not show.
Here is a very simple example. You can build from it:
#include <gtkmm.h>
#include <iostream>
class MyShortcutsWindow : public Gtk::ShortcutsWindow
{
public:
MyShortcutsWindow();
private:
Gtk::ShortcutsShortcut m_shortcut;
Gtk::ShortcutsGroup m_group;
Gtk::ShortcutsSection m_section;
};
MyShortcutsWindow::MyShortcutsWindow()
{
// Prints Gtkmm version:
std::cout << "Gtkmm version : "
<< gtk_get_major_version() << "."
<< gtk_get_minor_version() << "."
<< gtk_get_micro_version()
<< std::endl;
// 1. Create shorcut:
// -------------------------------------------------------------
// Set title:
auto shortcutTitle = m_shortcut.property_title();
shortcutTitle.set_value("Hit that to search");
// Set type:
auto shortcutType = m_shortcut.property_shortcut_type();
shortcutType.set_value(Gtk::SHORTCUT_ACCELERATOR);
// Set accelerator:
auto shortcutAccelerator = m_shortcut.property_accelerator();
shortcutAccelerator.set_value("<Ctrl>f");
// 2. Create shortcut group:
// -------------------------------------------------------------
m_group.add(m_shortcut);
// 3. Create shortcut section:
// -------------------------------------------------------------
m_section.add(m_group);
// Make sure your section is visible. I have found if this is
// not called, your section won't show until you have tried a
// search first (weird):
auto sectionVisibility = m_section.property_visible();
sectionVisibility.set_value(true);
// 4. Add the section to the window:
// -------------------------------------------------------------
add(m_section);
}
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create(argc, argv, "so.question.q66123196");
MyShortcutsWindow window;
window.show_all();
return app->run(window);
}
It works with Gtkmm version 3.22.30 in my case. You need at most version 3.20 according to the docs.
Following up on BobMorane's answer: Calling show_all() on your Gtk::ShortcutsSection object will provide the same result as setting property_visible to true.
In the example provided:
m_section.add(m_group);
m_section.show_all();
// 4. Add the section to the window:
// -------------------------------------------------------------
add(m_section);
I implemented a native File Picker on BlackBerry 10, after a bit of messing around it finally recognised the class, it opens fine and returns the file Address on the console but it looks like two signals are not working properly, baring in mind this is pretty much a straight copy of code from BlackBerry 10 docs.
using namespace bb::cascades::pickers;
void Utils::getFile() const{
FilePicker* filePicker = new FilePicker();
filePicker->setType(FileType::Music);
filePicker->setTitle("Select Sound");
filePicker->setMode(FilePickerMode::Picker);
filePicker->open();
// Connect the fileSelected() signal with the slot.
QObject::connect(filePicker,
SIGNAL(fileSelected(const QStringList&)),
this,
SLOT(onFileSelected(const QStringList&)));
// Connect the canceled() signal with the slot.
QObject::connect(filePicker,
SIGNAL(canceled()),
this,
SLOT(onCanceled()));
}
I wanted it to return the file url to qml with this (works fine with QFileDialog but that wouldn't recognise on my SDK) var test=utils.getFile()
if(test=="") console.debug("empty")
else console.debug(test)
But I'm getting these messages from the console: Object::connect: No such slot Utils::onFileSelected(const QStringList&) in ../src/Utils.cpp:27
Object::connect: No such slot Utils::onCanceled() in ../src/Utils.cpp:33
It is returning undefined from the else in the qml function when it opens,
Does anyone know where I cocked up or how I could get QFileDialog class to be found by the SDK?
I just wanted to give you a bit of an explanation in case you're still having some troubles. The concept's in Qt were a little foreign to me when I started in on it as well.
There are a couple ways you can do this. The easiest would probably be the pure QML route:
import bb.cascades 1.2
import bb.cascades.pickers 1.0
Page {
attachedObjects: [
FilePicker {
id: filePicker
type: FileType.Other
onFileSelected: {
console.log("selected files: " + selectedFiles)
}
}
]
Container {
layout: DockLayout {
}
Button {
id: launchFilePicker
text: qsTr("Open FilePicker")
onClicked: {
filePicker.open();
}
}
}
}
When you click the launchFilePicker button, it will invoke a FilePicker. Once a file is selected, the fileSelected signal will be fired. The slot in this case is the onFileSelected function (predefined), which logs the filepaths of the files that were selected (a parameter from the signal) to the console.
The C++ route is a little more work, but still doable.
If your class file was called Util, then you'd have a Util.h that looks something like this:
#ifndef UTIL_H_
#define UTIL_H_
#include <QObject>
class QStringList;
class Util : public QObject
{
Q_OBJECT
public:
Util(QObject *parent = 0);
Q_INVOKABLE
void getFile() const;
private Q_SLOTS:
void onFileSelected(const QStringList&);
void onCanceled();
};
#endif /* UTIL_H_ */
Note the Q_INVOKABLE getFile() method. Q_INVOKABLE will eventually allow us to call this method directly from QML.
The corresponding Util.cpp would look like:
#include "Util.h"
#include <QDebug>
#include <QStringList>
#include <bb/cascades/pickers/FilePicker>
using namespace bb::cascades;
using namespace bb::cascades::pickers;
Util::Util(QObject *parent) : QObject(parent)
{
}
void Util::getFile() const
{
FilePicker* filePicker = new FilePicker();
filePicker->setType(FileType::Other);
filePicker->setTitle("Select a file");
filePicker->setMode(FilePickerMode::Picker);
filePicker->open();
QObject::connect(
filePicker,
SIGNAL(fileSelected(const QStringList&)),
this,
SLOT(onFileSelected(const QStringList&)));
QObject::connect(
filePicker,
SIGNAL(canceled()),
this,
SLOT(onCanceled()));
}
void Util::onFileSelected(const QStringList &stringList)
{
qDebug() << "selected files: " << stringList;
}
void Util::onCanceled()
{
qDebug() << "onCanceled";
}
To make your Q_INVOKABLE getFile() method available to QML, you'd need to create an instance and set it as a ContextProperty. I do so in my applicationui.cpp like so:
Util *util = new Util(app);
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
qml->setContextProperty("_util", util);
Then, you can call this Q_INVOKABLE getFile() method from QML:
Page {
Container {
layout: DockLayout {}
Button {
id: launchFilePicker
text: qsTr("Open FilePicker")
onClicked: {
_util.getFile();
}
}
}
}
Like Richard says, most of the documentation covers how to create signals/slots, so you could review that, but also have a look at some Cascades-Samples on Git.
Hope that helps!!!
I'm making a text editor using GTK3 in Vala. I have a Gtk.MenuBar in a Gtk.Window and I want to use accelerators to easily activate its Gtk.MenuItems. But I want the user to be able to change the key combinations, so I'm loading the accelerators specifications from a file using the method Gtk.AccelMap.load("accels"). However, after calling this method, the accelerators are not loaded: the menu items don't have AccelLabels and are not activated when I press the key combinations. Here are the two files I'm working on. The first file contains a small version of my application (to show what I'm trying to do) and the second one is the accels file from which I load the accels specifications, and they must be in the same directory.
main.vala
// Compile me with: valac main.vala -o main --pkg gtk+-3.0
public class MyWindow: Gtk.Window {
public MyWindow() {
this.set_default_size(500, 500);
var main_box = new Gtk.VBox(false, 0);
this.add(main_box);
var accel_group = new Gtk.AccelGroup();
this.add_accel_group(accel_group);
// Load the accelerators from the file
Gtk.AccelMap.load("accels");
// Create the action
var quit_action = new Gtk.Action("file-quit", "Quit", "Quit the application", null);
quit_action.activate.connect(()=>{
Gtk.main_quit();
});
quit_action.set_accel_group(accel_group);
quit_action.set_accel_path("<MyWindow>/File/Quit");
// Menubar
var menubar = new Gtk.MenuBar();
main_box.pack_start(menubar, false, false, 0);
var file = new Gtk.MenuItem.with_label("File");
menubar.add(file);
var file_menu = new Gtk.Menu();
file.set_submenu(file_menu);
var quit_mi = (Gtk.MenuItem)quit_action.create_menu_item();
file_menu.append(quit_mi);
// Label
var label = new Gtk.Label("My Window");
main_box.pack_start(label, true, true, 0);
this.destroy.connect(Gtk.main_quit);
}
}
int main(string[] args) {
Gtk.init(ref args);
var win = new MyWindow();
win.show_all();
Gtk.main();
return 0;
}
"accels" file
; main GtkAccelMap rc-file -*- scheme -*-
; this file is an automated accelerator map dump
;
; (gtk_accel_path "<MyWindow>/File/Quit" "<Control>q")
So, why is this not working? What do I have to do before or after loading the accel file?
PS: I don't want to use a Gtk.UIManager.
See : https://docs.xfce.org/faq#keyboard_related
"
This functionality has been disabled since GTK3 which means that Xfce apps that have migrated to GTK3 (such as xfce4-terminal) do not support it.
Refer to specific app's documentation to learn how to configure its shortcuts.
"