Awesomium WebControl not showing - visual-studio-2010

Sorry if this sounds a little noobish, but I just installed Awesomium SDK, added references to the project, and I can't find the "WebControl" in the ToolBox. What am I doing wrong?

All you have to do is run the setup to uninstall and reinstall it in the assembly folder.
http://wiki.awesomium.net/getting-started/setting-up-on-windows.html

This may help, go to your project properties and check the target framework.It should be .Net Framework 4 client profile or above

You should create WebView, add it to form, set it location and size and set source URI!
try to include namespaces:
using Awesomium;
using Awesomium.Windows.Forms;
using Awesomium.Core;
static class Program {
static Form1 f1 = new Form1();
static Form fm = new Form {};
static WebBrowser wb = new WebBrowser { Dock = DockStyle.Fill};
//private static WebView wv;
static WebControl wc = new WebControl{Visible = true};
//static WebView wv;// = new WebView(fm.Handle);
[STAThread]
static void Main(string[] args) {
//f1.ShowDialog(); return;
wc.ViewType = WebViewType.Window;
wc.Location = new System.Drawing.Point(0,0);
wc.Size = new System.Drawing.Size(1000,1000);
fm.Controls.Add(wc);
//wv = new WebView(fm.Handle);
//fm.Controls.Add(wv.con);
wc.Source = new Uri("https://stackoverflow.com");
Task k = new Task(delegate {
Thread.Sleep(200);
try {
fm.Invoke(new MethodInvoker(delegate {
try {
MessageBox.Show(wc.Source.ToString());
} catch {
MessageBox.Show("2");
}
}));
} catch {
MessageBox.Show("1");
}
});
k.Start();
fm.ShowDialog();
}//main

Related

I can't use a Winforms Control created with a Class

I was looking for a Circular Picture Box for my app and I stumbled across this code (IT IS NOT MINE) and I've tried as many times as I could but I can't find any mistake. I have followed every step that was made in the tutorial for this Rounded Picture Box so it can't be a miscopy because it was working perfectly in the tutorial.
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace New_Radio_Barcelona.Controls
{
class RashiCircularPictureBox : PictureBox
{
private int border = 2;
private Color colorBorder = Color.RoyalBlue;
private Color colorBorder2 = Color.HotPink;
private DashStyle borderstyle = DashStyle.Solid;
private DashCap borderCap = DashCap.Flat;
private float gradiant = 50f;
public RashiCircularPictureBox()
{
this.Size = new Size(95, 95);
this.SizeMode = PictureBoxSizeMode.StretchImage;
}
public int Border
{
get
{
return border;
}
set
{
border = value;
this.Invalidate();
}
}
public Color ColorBorder
{
get
{
return colorBorder;
}
set
{
colorBorder = value;
this.Invalidate();
}
}
public Color ColorBorder2
{
get
{
return colorBorder2;
}
set
{
colorBorder2 = value;
this.Invalidate();
}
}
public DashStyle Borderstyle
{
get
{
return borderstyle;
}
set
{
borderstyle = value;
this.Invalidate();
}
}
public DashCap BorderCap
{
get
{
return borderCap;
}
set
{
borderCap = value;
this.Invalidate();
}
}
public float Gradiant
{
get
{
return gradiant;
}
set
{
gradiant = value;
this.Invalidate();
}
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.Size = new Size(this.Width, this.Width);
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
var graphic = pe.Graphics;
var rect = Rectangle.Inflate(this.ClientRectangle, -1, -1);
var rectborder = Rectangle.Inflate(rect, -border, -border);
var size = border > 0 ? border * 3 : 1;
using (var bordercolorG = new LinearGradientBrush(rectborder, colorBorder, colorBorder2, gradiant))
using (var path = new GraphicsPath())
using (var pen = new Pen(this.Parent.BackColor, border))
using (var penborder = new Pen(bordercolorG, size))
{
graphic.SmoothingMode = SmoothingMode.AntiAlias;
penborder.DashStyle = borderstyle;
penborder.DashCap = borderCap;
path.AddEllipse(rect);
this.Region = new Region(path);
graphic.DrawEllipse(pen, rect);
if (border > 0)
{
graphic.DrawEllipse(penborder, rectborder);
}
}
}
}
}
I compile the project and then try to add it to the Design tab as shown in the tutorial. It says it could not be loaded. I was trying to understand what is not working properly but I still do not find the mistake. Some help plis?
Another aspect to take into consideration is the fact that in class RashiCircularPictureBox : PictureBox puts 1 reference above the code and in public RashiCircularPictureBox() it says 0 references. It may be for this but I'm no expert on Classes and I'm stuck in this stupidity. if anyone could clear my mind about this issue I would be so grateful about it
The designer in most versions of Visual Studio up until recently has been a 32-bit process. So if the control was built as 64-bit, it wouldn’t be able to load it at design-time, but VS would still be able to create 64-bit applications that can use the 64-bit control at runtime.
This means if you build your control as 32-bit or AnyCPU, it should solve the design-time loading problem.
The release notes of Visual Studio 2022 version 17.0.0 state that “devenv.exe is now 64-bit only”. I haven’t tried this myself, but it probably means you can now use 64-bit controls at design time with the newer versions of VS.
In all cases, AnyCPU should work.

How do I enable WebGL in Xamarin.Forms WebView on UWP?

I’m new to Xamarin.Forms and tried using WebView on my Windows 10 x64 v1803 machine with UWP but I can’t see how to get it to work with WebGL.
Sites which use WebGL either display a message that “Your video card does not support WebGL or just don’t display and graphical content at all.
Is this a limitation of UWP or WebView itself?
Is it a WebView configuration issue?
WebGL works in all other browsers on this machine.
UWP WebView control is support WebGL. There is similar issue case in msdn you could refer. Please try to use SeparateProcess mode WebView to replace the default one.
public MainPage()
{
this.InitializeComponent();
var MyWebView = new WebView(WebViewExecutionMode.SeparateProcess);
MyWebView.Source = new Uri("http://cycleblob.com/");
this.RootGrid.Children.Add(MyWebView);
}
I had the same problem, but with the newer Xamarin Forms it took a little more poking around to get this took work right. However, I do like that they moved the native WebView resolver back to the responsibility of the UWP/iOS/Android project (as a native XAML object) instead of using code branching with compiler directives in the Shared project.
Start by creating a HybridWebView class in the shared project to use as your WebForm view object:
public class HybridWebView : Xamarin.Forms.WebView
{
Action<string> action;
public static readonly BindableProperty UriProperty = BindableProperty.Create(
propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(HybridWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
public void RegisterAction(Action<string> callback)
{
action = callback;
}
public void Cleanup()
{
action = null;
}
public void InvokeAction(string data)
{
if (action == null || data == null)
{
return;
}
action.Invoke(data);
}
}
Then in the UWP project, create a custom renderer, which will construct the native WebView and relay the events back to the WebForms object in the Shared project:
Put this at the top of the namespace, to link the HybridWebView with the Custom Renderer:
[assembly: ExportRenderer(typeof(HybridWebView), typeof(WebViewRenderer2))]
Then create the renderer class (for the IOS and android projects, if you leave this class out, it defaults to the standard native controls which seem to work fine for me):
public class WebViewRenderer2 : ViewRenderer<Xamarin.Forms.WebView, Windows.UI.Xaml.Controls.WebView>, IWebViewDelegate
{
Windows.UI.Xaml.Controls.WebView _control;
public void LoadHtml(string html, string baseUrl)
{
}
public void LoadUrl(string url)
{
}
protected override void Dispose(bool disposing)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
if (_control == null) {
_control = new Windows.UI.Xaml.Controls.WebView(WebViewExecutionMode.SeparateProcess);
SetNativeControl(_control);
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
var xamWebView = sender as HybridWebView;
switch(e.PropertyName.ToLower())
{
case "source":
var urlSource = xamWebView.Source as Xamarin.Forms.UrlWebViewSource;
_control.Source = new Uri(urlSource.Url);
break;
case "width":
_control.Width = xamWebView.Width;
break;
case "height":
_control.Height = xamWebView.Height;
break;
case "isfocused":
var focused = xamWebView.IsFocused;
if (focused)
_control.Focus(FocusState.Programmatic);
else
_control.Focus(FocusState.Unfocused);
break;
}
}
}
You can also use the Custom Renderer to inject scripts, and you can use it to communicate from the native webview back to the Xamarin App, as seen here: HybridWebView Communication

Sharing targeted xamarin forms

I use the following command to share a link, but with this command opens a box with apps for me to share. I want when I share it already go straight to facebook, without going through this box
void OnTapped4(object sender, EventArgs args)
{
CrossShare.Current.ShareLink(link, "teste", titulo);
}
Need to do direct shares to facebook, whatsapp, twitter and email
I have this command plus it works only on xamarin android, in xamarin forms it would no work
Intent sendIntent = new Intent();
sendIntent.SetAction(Intent.ActionSend);
sendIntent.PutExtra(Intent.ExtraText,"titulo");
sendIntent.SetType("text/plain");
sendIntent.SetPackage("com.facebook.orca");
StartActivity(sendIntent);
I found the following example where I did on android and it worked, now I want to do this in IOS how can I get it to go to whatsapp
Android
public class ShareService : IShareService
{
public void SharePageLink(string url)
{
var context = Forms.Context;
Activity activity = context as Activity;
Intent share = new Intent(Intent.ActionSend);
share.SetType("text/plain");
share.AddFlags(ActivityFlags.ClearWhenTaskReset);
share.PutExtra(Intent.ExtraSubject, "Brusselslife");
share.SetPackage("com.whatsapp");
share.PutExtra(Intent.ExtraText, url);
activity.StartActivity(Intent.CreateChooser(share, "Share link!"));
}
}
In IOS where to put this 'com.whatsapp'
public class ShareService : IShareService
{
public void SharePageLink(string url)
{
var window = UIApplication.SharedApplication.KeyWindow;
var rootViewController = window.RootViewController;
//SetPackage
var activityViewController = new UIActivityViewController(new NSString[] { new NSString(url) }, null);
activityViewController.ExcludedActivityTypes = new NSString[] {
UIActivityType.AirDrop,
UIActivityType.Print,
UIActivityType.Message,
UIActivityType.AssignToContact,
UIActivityType.SaveToCameraRoll,
UIActivityType.AddToReadingList,
UIActivityType.PostToFlickr,
UIActivityType.PostToVimeo,
UIActivityType.PostToTencentWeibo,
UIActivityType.PostToWeibo
};
rootViewController.PresentViewController(activityViewController, true, null);
}
}

How to show iOS add contact screen from Xamarin Forms?

I'm trying to show the iOS add contact screen using Xamarin Forms. From what I can see Xamarin Forms does not support this out of the box but Xamarin iOS does. Unfortunately I can't get them to work together. What I mean by "together" is that I need get access to NavigationController from Xamarin Forms Page.
Can this be done?
I have a sample solution that demonstrates the problem here: https://github.com/pawelpabich/XamarinFormsContacts. I also put the most important code below.
public void ShowContact(NavigationPage page)
{
var newPersonController = new ABNewPersonViewController();
var person = new ABPerson();
person.FirstName = "John";
person.LastName = "Doe";
newPersonController.DisplayedPerson = person;
var controller = page.CreateViewController();
//!!!!---> controller.NavigationController is null !!!!!<----
controller.NavigationController.PushViewController(newPersonController, true);
}
I updated the repo and it now contains code that works.
There is a UINavigationController when using Xamarin.Forms (when using a NavigationPage), but you have to search for it. This was the only way I could get a hold of it. Those other methods, CreateViewController and RendererFactory actually create a new ViewController which isn't what you wanted.
public void ShowContact(NavigationPage page)
{
var newPersonController = new ABNewPersonViewController();
var person = new ABPerson();
person.FirstName = "John";
person.LastName = "Doe";
newPersonController.Title = "This is a test";
newPersonController.DisplayedPerson = person;
UINavigationController nav = null;
foreach (var vc in
UIApplication.SharedApplication.Windows[0].RootViewController.ChildViewControllers)
{
if (vc is UINavigationController)
nav = (UINavigationController)vc;
}
nav.PresentModalViewController(new UINavigationController (newPersonController), true);
}
I also attempted to Create a PersonPage and PersonPageRenderer, as that would be the cleanest solution, but I couldn't get it working. This could work if you spent some time.
[assembly: ExportRenderer(typeof(PersonPage), typeof(PersonPageRenderer))]
public class PersonPageRenderer : ABNewPersonViewController, IVisualElementRenderer, IDisposable, IRegisterable
Pawel, the problem is that when you use Xamarin.Forms no NavigationController is created (as I know at least in X.F 1.3+, maybe Michael will prove me wrong). If you want to create new address boo element you can use this approach - How do you add contacts to the iPhone Address book with monotouch?
Because iOS Add Contact screen is a Native iOS API and your application logic is in a PCL you need to use a DependancyService.
1) To do this in the PCL create a Interface which provides the functionality, like
public interface ILocalAddContact
{
void DisplayContactScreen(Contact contact)
}
2) Implement the Interface in the Native Applications:
public class LocalAddContactiOS : ILocalAddContact
{
public void DisplayContactScreen(Contact contact)
{
//... do iOS Magic
}
}
3) Register the Dependancy in the Top of the Native File
[assembly: Xamarin.Forms.Dependency(typeof(LocalAddContactiOS))]
4) Obtain the Dependancy from the iOS Project from the
var addContact = DependencyService.Get<ILocalAddContact> ();
addContact.DisplayContactScreen (contact);
If you take a look at this sample application on github, it's very similar (but is used for CreateCalendar).
Ok, this is how I finally implemented. I created UINavigationController manually and use it for navigations outside Xamarin.Forms.
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
using Xamarin.Forms;
using AddressBookUI;
using AddressBook;
namespace TestContacts.iOS
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init ();
window = new UIWindow(UIScreen.MainScreen.Bounds);
var nav =
new UINavigationController(new App ().MainPage.CreateViewController());
ContactsShared.Instance = new TouchContacts (nav);
window.RootViewController = nav;
window.MakeKeyAndVisible();
return true;
}
}
public class TouchContacts : IContactsShared {
UINavigationController nav;
public TouchContacts(UINavigationController nav){
this.nav = nav;
}
public void Show() {
var newPersonController = new ABNewPersonViewController();
newPersonController.NewPersonComplete +=
(object sender, ABNewPersonCompleteEventArgs e) =>
{
nav.PopViewController(true);
};
var person = new ABPerson();
person.FirstName = "John";
person.LastName = "Doe";
newPersonController.DisplayedPerson = person;
nav.PushViewController(newPersonController, true);
}
}
}

How to read the contents of a screen from another application [Office Communicator]

Knowing the hwnd of the window, how do I read the contents of this? Before anyone ask me, I'm trying to get the text that was used in the Communicator window.
Below is the code I found on the Internet.
The code is not mine.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace EventFun
{
class EventHookUp
{
CommunicatorAPI.Messenger mCommunicator = null;
static void Main(string[] args)
{
EventHookUp hu = new EventHookUp();
hu.InitializeEventHocks();
Console.ReadKey();
}
public void InitializeEventHocks()
{
mCommunicator = new CommunicatorAPI.Messenger();
mCommunicator.OnIMWindowCreated += new CommunicatorAPI.DMessengerEvents_OnIMWindowCreatedEventHandler(mCommunicator_OnIMWindowCreated);
mCommunicator.OnIMWindowDestroyed += new CommunicatorAPI.DMessengerEvents_OnIMWindowDestroyedEventHandler(mCommunicator_OnIMWindowDestroyed);
}
void mCommunicator_OnIMWindowCreated(object pIMWindow)
{
CommunicatorAPI.IMessengerConversationWndAdvanced stpIMWindow = pIMWindow as CommunicatorAPI.IMessengerConversationWndAdvanced;
//stpIMWindow.History;
long Hwnd = (long)stpIMWindow.HWND;
Console.WriteLine("New IM Window Created : {0}", Hwnd);
CommunicatorAPI.IMessengerContacts contactList = (CommunicatorAPI.IMessengerContacts)stpIMWindow.Contacts;
StringBuilder sb = new StringBuilder();
foreach (CommunicatorAPI.IMessengerContact imc in contactList)
{
sb.Append(imc.FriendlyName);
sb.Append(Environment.NewLine);
}
Console.WriteLine(sb.ToString());
}
void mCommunicator_OnIMWindowDestroyed(object pIMWindow)
{
Console.WriteLine("IM Window Destroyed.");
}
}
}
It sounds like you are trying to get the conversation text history from the conversation window? If so, George Durzi has an excellent blog post on this.
As this blog post is not available, I used below method to retrieve the conversation history:
object obj = msgrAdv.StartConversation(
CONVERSATION_TYPE.CONVERSATION_TYPE_IM, // Type of conversation
sipUris, // object array of signin names for having multiple conversations or just a string
null,
"Test",
"1",
null);
imWindowHandle = long.Parse(obj.ToString());
if (imWindow == null) //If there is already an open window...
{
imWindow = (IMessengerConversationWndAdvanced)msgrAdv.InstantMessage(sipUris);
}
//else there was no open window, we have opened the window using "msgrAdv.StartConversation" so there is a imWindow associated which is implemented in communicator_OnIMWindowCreated.
//and then...
string history = imWindow.History;

Resources