Geckofx closing and reopening in c# - c#

What is needed : I need it to close and reopen the browser, I've tried a couple of things. Winform, c#.
What i've tried :
using (Viewer = new GeckoWebBrowser())
{
Viewer.Dock = DockStyle.Bottom;
Viewer.Size = new Size(217, 257);
Viewer.Location = new Point(0, 90);
Viewer.Enabled = true;
Viewer.Visible = true;
Xpcom.Initialize("xulrunner");
GeckoPreferences.User["browser.xul.error_pages.enabled"] = false;
GeckoPreferences.User["security.enable_ssl2"] = true;
GeckoPreferences.User["security.default_personal_cert"] = "Ask Never";
GeckoPreferences.User["security.warn_entering_weak"] = true;
GeckoPreferences.User["security.warn_viewing_mixed"] = true;
GeckoPreferences.User["dom.disable_open_during_load"] = true;
GeckoPreferences.User["dom.allow_scripts_to_close_windows"] = true;
GeckoPreferences.User["dom.popup_maximum"] = 0;
GeckoPreferences.User["dom.max_script_run_time"] = 0;
GeckoPreferences.User["extensions.blocklist.enabled"] = false;
Viewer.BringToFront();
Viewer.Navigate("http://google.com");
Viewer.Dispose();
}
What is the problem?
It isn't showing up on the winform window.
Also i tried it with a windows control in the winform and using Viewer.Dispose(); destroyed the control completely and i wasn't able to access it any more.

Related

C# enabling or disabling control

So, I'm losing my mind over a bug in my software.
I have this code, I use it 2 times in my software, the other function similar (with a different name) works normally. But this one is inverted...
I mean by that : Instead of enabling the controls when the groupbox.text contains "INC", it disable them.
Any idea on what is going on?
`private void Enable_disableSTM()
{
if (STM_groupBox.Text.Contains("INC"))
{
STM_radioButton_appel.Enabled = true;
STM_radioButton_autre.Enabled = true;
STM_radioButton_resolution.Enabled = true;
STM_Textbox_SR.Enabled = true;
STM_textBox_remarque.Enabled = true;
STM_Dropdown_Sendto.Enabled = true;
STM_pictureBox_Boutonenvoyer.Enabled = true;
}
else
{
STM_radioButton_appel.Enabled = false;
STM_radioButton_autre.Enabled = false;
STM_radioButton_resolution.Enabled = false;
STM_Textbox_SR.Enabled = false;
STM_textBox_remarque.Enabled = false;
STM_Dropdown_Sendto.Enabled = false;
STM_pictureBox_Boutonenvoyer.Enabled = false;
}
} `
Edit :
Like I said, in my software I have this other function that is working fine. I tried also to change my IF to STM_Textbox_reademail.Text != "" and it's still not working correctly. It's inverted. Enabling when it should not and Disabling too.
`if (SQ_TextBox_reademail.Text != "")
{
SQ_radioButton_appel.Enabled = true;
SQ_radioButton_autre.Enabled = true;
SQ_radioButton_resolution.Enabled = true;
SQ_Textbox_SR.Enabled = true;
SQ_textBox_remarque.Enabled = true;
SQ_Dropdown_Sendto.Enabled = true;
SQ_pictureBox_Boutonenvoyer.Enabled = true;
}
else
{
SQ_radioButton_appel.Enabled = false;
SQ_radioButton_autre.Enabled = false;
SQ_radioButton_resolution.Enabled = false;
SQ_Textbox_SR.Enabled = false;
SQ_textBox_remarque.Enabled = false;
SQ_Dropdown_Sendto.Enabled = false;
SQ_pictureBox_Boutonenvoyer.Enabled = false;
} `
Edit 2 : Okay... I figured out something that works. I'm calling my function at a different place now and it's working. Still does not make sense why I can call the other one at the same place and it works but this one doesn't... but hey... now it works! thanks all!
Your problem is that you are checking if a string contains the "INC" word in a case sensitive way the solution is changing the if statement to check in the string the inc word ignoring the case :
private void Enable_disableSTM()
{
if (STM_groupBox.Text.IndexOf("INC", StringComparison.OrdinalIgnoreCase) >= 0;)
{
STM_radioButton_appel.Enabled = true;
STM_radioButton_autre.Enabled = true;
STM_radioButton_resolution.Enabled = true;
STM_Textbox_SR.Enabled = true;
STM_textBox_remarque.Enabled = true;
STM_Dropdown_Sendto.Enabled = true;
STM_pictureBox_Boutonenvoyer.Enabled = true;
}
else
{
STM_radioButton_appel.Enabled = false;
STM_radioButton_autre.Enabled = false;
STM_radioButton_resolution.Enabled = false;
STM_Textbox_SR.Enabled = false;
STM_textBox_remarque.Enabled = false;
STM_Dropdown_Sendto.Enabled = false;
STM_pictureBox_Boutonenvoyer.Enabled = false;
}
}
Okay... I figured out something that works. I'm calling my function at a different place now and it's working. Still does not make sense why I can call the other one at the same place and it works but this one doesn't... but hey... now it works! thanks all!

How do I change my icon of the form on the click of a button?

I am using a form skin and instead of removing everything including the form skin I have been trying to make the form change the icon itself on startup. I have bitmap versions of my logo and when i try to reference those i get the error: Cannot implicitly convert type 'System.Drawing.Bitmap' to 'System.Drawing.Icon'
I have tried adding an icon to my resources and trying to reference it, however, only my bitmaps are able to be referenced.
public Main2()
{
InitializeComponent();
Main2 f1 = new Main2();
f1.Text = "Chaos V2.0.1c";
f1.Icon = Properties.Resources.Logo; //problematic code (line 44)
//My Tab Controls
HomeTabControl.Visible = true;
FullLuaTabControl.Visible = false;
CommandTabControl.Visible = false;
VIPServerTabControl.Visible = false;
JailbreakTabControl.Visible = false;
PhantomForcesTabControl.Visible = false;
MM2TabControl.Visible = false;
RoCitizensTabControl.Visible = false;
BoogaBoogaTabControl.Visible = false;
PrisonLifeTabControl.Visible = false;
BuildABoatTabControl.Visible = false;
LumberTycoon2TabControl.Visible = false;
MeepCityTabControl.Visible = false;
VehicleSimulatorTabControl.Visible = false;
SuperPowerTrainingTabControl.Visible = false;
BeeSwarmSimulatorTabControl.Visible = false;
WeightLiftingTabControl.Visible = false;
MiningSimulatorTabControl.Visible = false;
BlobSimulatorTabControl.Visible = false;
IceCreamSimulatorTabControl.Visible = false;
PetSimulatorTabControl.Visible = false;
StrucidTabControl.Visible = false;
CounterBloxTabControl.Visible = false;
ApocalypseTabControl.Visible = false;
FullLuaScriptsTabControl.Visible = false;
SettingsTabControl.Visible = false;
}
I get the error: 'Resources' does not contain a definition for 'Logo' (Line 44)
Check if your Icon in resources is really called Logo.
You could change Bitmap to Icon, but I don't know if you will be satisfied with result.
public Icon ToIcon(Bitmap bmp)
{
IntPtr hicon = bmp.GetHicon();
Icon icon = Icon.FromHandle(hicon);
DestroyIcon(hicon); // prevent memory leak.
return icon;
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
extern static bool DestroyIcon(IntPtr handle);

Using AutoLayout and UIScrollView programmatically

I am trying to make a copy of the answer from this question here: Xamarin iOS: Auto Layout within scroll view? but without using the interface builder. The code is simple, I have _scrollView which has background color green. Then I have _contentView which has background color red. I add _contentView to _scrollView and I add _scrollView to View in the ViewController. When I run this, all I get is Green controller, the red one never appears inside of it.
public async override void ViewDidLoad()
{
base.ViewDidLoad();
//ui
View.BackgroundColor = UIColor.White;
//views
_scrollView = new UIScrollView();
_scrollView.BackgroundColor = UIColor.Green;
_scrollView.TranslatesAutoresizingMaskIntoConstraints = false;
_contentView = new UIView();
_contentView.TranslatesAutoresizingMaskIntoConstraints = false;
_contentView.BackgroundColor = UIColor.Red;
var label = new UILabel();
label.TranslatesAutoresizingMaskIntoConstraints = false;
label.Text = "Text";
_contentView.AddSubview(label);
_scrollView.AddSubview(_contentView);
View.AddSubviews(new UIView[] { _scrollView });
_scrollView.TopAnchor.ConstraintEqualTo(View.TopAnchor, 100).Active = true;
_scrollView.LeftAnchor.ConstraintEqualTo(View.LeftAnchor, 20).Active = true;
_scrollView.RightAnchor.ConstraintEqualTo(View.RightAnchor, -20).Active = true;
_scrollView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor, -100).Active = true;
_contentView.TopAnchor.ConstraintEqualTo(_contentView.Superview.TopAnchor).Active = true;
_contentView.RightAnchor.ConstraintEqualTo(_contentView.Superview.RightAnchor).Active = true;
_contentView.LeftAnchor.ConstraintEqualTo(_contentView.Superview.LeftAnchor).Active = true;
_contentView.BottomAnchor.ConstraintEqualTo(_contentView.Superview.BottomAnchor).Active = true;
_contentView.WidthAnchor.ConstraintEqualTo(_contentView.Superview.WidthAnchor).Active = true;
label.TopAnchor.ConstraintEqualTo(label.Superview.TopAnchor, 100).Active = true;
label.BottomAnchor.ConstraintEqualTo(label.Superview.BottomAnchor, 100).Active = true;
label.LeftAnchor.ConstraintEqualTo(label.Superview.LeftAnchor, 100).Active = true;
label.RightAnchor.ConstraintEqualTo(label.Superview.RightAnchor, 100).Active = true;
}
You need to constraint the width of the _contentView to the View instead of _scrollView. Change this constraint:
_contentView.WidthAnchor.ConstraintEqualTo(_contentView.Superview.WidthAnchor).Active = true;
For this one:
_contentView.WidthAnchor.ConstraintEqualTo(View.WidthAnchor).Active = true;
Other than that I highly recommend you to use a helper library for using AutoLayout programatically. Check out FluentLayout
The only way I was able to make it work was by adding BottomAnchor to the last UIView inside ContentView. I created a GitHub repo with demo code here

How to use a dynamic forms names in a class (C#.Net)

I had long time developing windows applications using VB.NET and one of thing that I was always use is:
Class (Test) and inside it there are some subs like the following:
VB.NET Code
Friend Sub FLoadKeyLock(ByVal FRMNAME As Object)
FRMNAME.Button3.Enabled = true;
FRMNAME.Button4.Enabled = true;
FRMNAME.Button1.Enabled = false;
FRMNAME.Button2.Enabled = false;
FRMNAME.Button5.Enabled = false;
FRMNAME.Button6.Enabled = false;
FRMNAME.Button7.Enabled = false;
FRMNAME.Button8.Enabled = false;
FRMNAME.Button9.Enabled = false;
FRMNAME.Button10.Enabled = false;
End Sub
Where FRMNAME refers to forms name that I send from different forms and I use (me) keyword to send current form name to apply that sub.
That was totally works fine in VB.NET but I cannot use it the same way in C#.NET.
C#.NET Code
internal void FLoadKeyLock (Form FRMNAME)
{
FRMNAME.Button3.Enabled = true;
FRMNAME.Button4.Enabled = true;
FRMNAME.Button1.Enabled = false;
FRMNAME.Button2.Enabled = false;
FRMNAME.Button5.Enabled = false;
FRMNAME.Button6.Enabled = false;
FRMNAME.Button7.Enabled = false;
FRMNAME.Button8.Enabled = false;
FRMNAME.Button9.Enabled = false;
FRMNAME.Button10.Enabled = false;
}
The Error is: System.Windows.Forms.Form' does not contain a definition for 'Button3' and no extension method 'Button3' accepting a first argument of type
And same error for all used buttons.
So I have two questions:
1 - How to use such a function in C#.NET?
2 - Why it's not working the same way as VB.NET?
As #Maarten said.
dynamic has solved my problem
internal void FLoadKeyLock (dynamic FRMNAME)
{
FRMNAME.Button3.Enabled = true;
FRMNAME.Button4.Enabled = true;
FRMNAME.Button1.Enabled = false;
FRMNAME.Button2.Enabled = false;
FRMNAME.Button5.Enabled = false;
FRMNAME.Button6.Enabled = false;
FRMNAME.Button7.Enabled = false;
FRMNAME.Button8.Enabled = false;
FRMNAME.Button9.Enabled = false;
FRMNAME.Button10.Enabled = false;
}

Showing Form from a thread not rendering perfectly

I am developing a chat application using jabber-net opensource library..
my aim is to display a form (chat window ) when a message is coming.
But when I use this code, Form appears in the task bar,,, not perfectly rendered...
seems like this... More over I can see the form only when I mousehover the Icon on taskbar (Hail Windows 7)... Any form are like this...
Click here for Output Image
my code is this...
public jabber.client.JabberClient jabberClient1;
jabberClient1.User = UserName;
jabberClient1.Password = Password;
jabberClient1.Resource = resource;
jabberClient1.AutoRoster = true;
jabberClient1.OnMessage += new MessageHandler(jabberClient1_OnMessage);
private void jabberClient1_OnMessage(object sender, jabber.protocol.client.Message msg)
{
try
{
chatWindow chw = new chatWindow();
chw.Left = 0;
chw.Top = 0;
chw.TopMost = true;
//chw.LoadChat(msg.From.User, msg.From.Bare, "0");
//chw.SetMessage(msg);
chw.Show();
}
}
you have to use chw.ShowDialog()
or use if invokerequired
private delegate void dlgInvokeRequired();
public void InvokeMethode()
{
if (this.InvokeRequired == true)
{
dlgInvokeRequired d = new dlgInvokeRequired(InvokeMethode);
this.Invoke(d);
} else
{
chatWindow chw = new chatWindow();
chw.Left = 0;
chw.Top = 0;
chw.TopMost = true;
//chw.LoadChat(msg.From.User, msg.From.Bare, "0");
//chw.SetMessage(msg);
chw.Show();
}
}
I have solved it myself...
I have to use
JabberClient1.InvokeControl = FormInstance;
and, the FormInstance should be shown Before the chat window appears....
ie, It can be the contact window (Roster)....

Categories

Resources