Caching Cookies in Awesomium - winforms

The Setup:
I am building an MDI Application. One of the Child Forms I call is a basic web browser using the Awesomium API.
Reference: BrowserControl.cs
public partial class BrowserControl : UserControl
{
public BrowserControl()
{
InitializeComponent();
}
private void OnControlLoad(object sender, EventArgs e)
{
String w3DataPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\HttpAgent";
if (!Directory.Exists(w3DataPath))
{
Directory.CreateDirectory(w3DataPath);
}
var webSession = WebCore.CreateWebSession(w3DataPath, WebPreferences.Default);
webControl.WebSession = webSession;
}
private void OnBackButtonClick(object sender, EventArgs e)
{
this.webControl.GoBack();
}
private void OnFwdButtonClick(object sender, EventArgs e)
{
this.webControl.GoForward();
}
private void OnReloadButtonClick(object sender, EventArgs e)
{
this.webControl.Reload(true);
}
private void OnStopButtonClick(object sender, EventArgs e)
{
this.webControl.Stop();
}
private void OnHomeButtonClick(object sender, EventArgs e)
{
this.webControl.GoToHome();
}
private void OnSearchButtonClick(object sender, EventArgs e)
{
String urlString = String.Format("https://www.google.com/#q={0}", HttpUtility.UrlEncode(this.SearchBox.Text));
this.webControl.Source = new System.Uri(urlString);
}
private void OnLoadingFrame(object sender, Awesomium.Core.LoadingFrameEventArgs e)
{
this.BrowserStatus.Text = "Loading " + e.Url;
}
private void OnLoadingComplete(object sender, Awesomium.Core.FrameEventArgs e)
{
this.BrowserStatus.Text = "Document Ready";
}
private void OnLoadingFailure(object sender, Awesomium.Core.LoadingFrameFailedEventArgs e)
{
this.BrowserStatus.Text = e.ErrorDescription;
}
}
Problem: Functionally the browser works just fine; however, it does not cache any persistent data locally. Note, I have established a valid DataPath using the Awesomium WebSession object as indicated in the above method OnControlLoad()
In terms of the validity of the path I define - I have confirmed it does exist on disk and it even appears the Awesomium WebSession adds a sub-directory called "cache". Unfortunately, none of the cookies I am getting in my web session are being saved locally. In fact - nothing is being cached. Both the HttpAgent directory I define and the cache directory the WebSession object defines are empty after deliberately logging into sites I know set cookies.
Any insight or help would be greatly appreciated. Thanks

I am not sure if it helps but try closing Awesomium "correctly": dispose WebControls, WebSession, call WebCore.Shutdown().

Related

Which textbox event will generate an email when the textbox is clicked?

All I want to do is input a Forename and a Surname into two textboxes and in the Email textbox generate an email address using the forename and surname. It isn't hard at all but none of the events I've tried have worked. I've even dummed it down so that if any of the events happen the email textbox should just say "hello".
None of these event have worked:
private void EmailAddressInputTextbox_TextChanged(object sender, EventArgs e)
{
EmailAddressInputTextbox.Text = ("Hello");
}
private void EmailAddressInputTextbox_GotFocus(object sender, EventArgs e)
{
EmailAddressInputTextbox.Text = ("Hello");
}
private void EmailAddressInputTextbox_Enter(object sender, EventArgs e)
{
EmailAddressInputTextbox.Text = ("Hello");
}
private void EmailAddressInputTextbox_Click(object sender, EventArgs e)
{
EmailAddressInputTextbox.Text = ("Hello");
}
Even tried:
private void SurnameInputTextbox_Leave(object sender, EventArgs e)
{
EmailAddressInputTextbox.Text = ("Hello");
}
Ideally I want the textbox to be filled when it has been clicked on and can be typed in but so far nothing happens...

background operation of user controller

I have prepared more than one UserControl for a windows program in XAML. Each user control works as a separate page. But I do page transitions in navigate class. In ".xaml.cs" when calling User control
Navigate.navigate (navigate_grid, new DeviceLayout ());
I'm using the line of code. But every time I create a new user control, the background functions don't work. How do I flip one instead of invoking a new user control each time?
class Navigate
{
public static void navigate(Grid grd, UserControl uc)
{
if (grd.Children.Count > 0)
{
grd.Children.Clear();
grd.Children.Add(uc);
}
else { grd.Children.Add(uc); }
}
}
Example navigate:
public SettingsView()
{
InitializeComponent();
Navigate.navigate(navigate_grid, new SystemLayout());
}
private void system_button_click(object sender, RoutedEventArgs e)
{
Navigate.navigate(navigate_grid, new SystemLayout());
previous_page.Text = "";
current_page.Text = "SİSTEM";
next_page.Text = "UYGULAMA";
}
private void application_button_click(object sender, RoutedEventArgs e)
{
Navigate.navigate(navigate_grid, new ApplicationLayout());
previous_page.Text = "SİSTEM";
current_page.Text = "UYGULAMA";
next_page.Text = "BAĞLANTI";
}
private void connection_button_click(object sender, RoutedEventArgs e)
{
Navigate.navigate(navigate_grid, new ConnectionLayout());
previous_page.Text = "UYGULAMA";
current_page.Text = "BAĞLANTI";
next_page.Text = "ÜRÜNLER";
}
private void product_button_click(object sender, RoutedEventArgs e)
{
Navigate.navigate(navigate_grid, new ProductsLayout());
previous_page.Text = "BAĞLANTI";
current_page.Text = "ÜRÜNLER";
next_page.Text = "CİHAZLAR";
}
private void device_button_click(object sender, RoutedEventArgs e)
{
Navigate.navigate(navigate_grid, new DeviceLayout());
previous_page.Text = "ÜRÜNLER";
current_page.Text = "CİHAZLAR";
next_page.Text = "YAZICILAR";
}
private void printer_button_click(object sender, RoutedEventArgs e)
{
Navigate.navigate(navigate_grid, new PrinterLayout ());
previous_page.Text = "CİHAZLAR";
current_page.Text = "YAZICILAR";
next_page.Text = "KULLANICILAR";
}
private void users_button_click(object sender, RoutedEventArgs e)
{
Navigate.navigate(navigate_grid, new UsersLayout());
previous_page.Text = "YAZICILAR";
current_page.Text = "KULLANICILAR";
next_page.Text = "BAKIM";
}
private void maintenance_button_click(object sender, RoutedEventArgs e)
{
Navigate.navigate(navigate_grid, new MaintenanceLayout());
previous_page.Text = "KULLANICILAR";
current_page.Text = "BAKIM";
next_page.Text = "HAKKINDA";
}
private void info_button_click(object sender, RoutedEventArgs e)
{
Navigate.navigate(navigate_grid, new InfoLayout());
previous_page.Text = "BAKIM";
current_page.Text = "HAKKINDA";
next_page.Text = "";
}
}
Not sure if I get what you mean.
When you change the UserControl with the use of any of those functions eg info_button_click you can't access this funtion anymore.
That would be the case, because your XAML and .cs file are one class, containing those funcitons. If you change the UserControl (XAML) you will also change the .cs file. Therefore you can't access those functions anymore.
You could probably get the behaviour you want if you bind the commands to a viewmodel, which you could then pass through the navigation as well?
Sry, I'm still not sure what exactly it is you're doing.

Create WPF TextBox that accepts only Text

private void txtLastName_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (!char.IsDigit((char)e.Key)) e.Handled = true;
}
But It not support all key in keyboard .
private void txtLastName_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(e.Text, "^[a-zA-Z]"))
{
e.Handled = true;
}
}
You must use IsLetter.
private void txtLastName_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (Char.IsLetter((char)e.Key)) e.Handled = true;
}
This thread is really old, but if someone still needs it, here is code that is working for me
(Edited a little bit Usman's code)
private void TextValidationTextBox(object sender, TextCompositionEventArgs e)
{
Regex regex = new Regex("[^a-zA-Z]+");
e.Handled = regex.IsMatch(e.Text);
}
And don't forget to put code below to TextBox that you want to accept only text ( in xaml )
PreviewTextInput="TextValidationTextBox"

How do I display a tooltip when focus is in a specific textbox?

For a textbox, I want to display a tooltip immediatly when the focus is in on the textbox, and stay there for the duration of the focus - not just when the mouse hovers over the textbox.
How can I do that?
The Enter and Leave events are probably useful here, and show it with a duration of 0 to keep it there.
private ToolTip tt;
private void textBox1_Enter(object sender, EventArgs e) {
tt = new ToolTip();
tt.InitialDelay = 0;
tt.IsBalloon = true;
tt.Show(string.Empty, textBox1);
tt.Show("I need help", textBox1, 0);
}
private void textBox1_Leave(object sender, EventArgs e) {
tt.Dispose();
}
Note: Calling the Show(...) method twice like in my example will force the "pointer" to point correctly to the control.
have tested, the event names:
private void textbox_Enter(object sender, EventArgs e)
{
toolTip1.Show("your tip here", textbox);
}
private void textbox_Leave(object sender, EventArgs e)
{
toolTip1.Hide(textbox);
}
tooltip is a control, needs to be added from toolbox.
using mouse hover and mouse leave events
private void textBox1_MouseHover(object sender, EventArgs e)
{
toolTip1.Show("your tip here", textBox2);
}
private void textBox1_MouseLeave(object sender, EventArgs e)
{
toolTip1.Hide(textBox2);
}
>
Windows Forms
public partial class FormWindow : Form
{
//Constructor
public FormWindow()
{
txtUrl.Text = "Enter text here";
txtUrl.ForeColor = Color.Gray;
txtUrl.GotFocus += TxtUrl_GotFocus;
txtUrl.LostFocus += TxtUrl_LostFocus;
}
private void TxtUrl_GotFocus(object sender, EventArgs e)
{
txtUrl.Text = "";
txtUrl.ForeColor = Color.Black;
}
private void TxtUrl_LostFocus(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(txtUrl.Text))
{
txtUrl.Text = "Enter text here";
txtUrl.ForeColor = Color.Gray;
}
}
}
Use a System.Windows.Forms.ToolTip and show it in textbox GotFocus event and Hide it in LostFocus event:
void textBox_GotFocus(object sender, EventArgs e)
{
toolTip.Show("your tip", textBox);
}
void textBox_LostFocus(object sender, EventArgs e)
{
toolTip.Hide(textBox);
}

Switching between multiple Cameras using Emgu CV

I have a quick question: I need to switch between the two camera on a tablet. Front and Back. By default, the Front camera is always used by Emgu CV.
Thanks.
Ok. There is a different constructor. I was building upon the 7 line demo for Emgu CV.
Using the correct overloaded constructor, this is what did the trick for me:
private Capture _capture;
private void InitCapture(Int32 _camIndex) {
try {
if (_capture != null) {
Application.Idle -= ProcessFrame;
}
_capture = new Capture(_camIndex);
Application.Idle += ProcessFrame;
}
catch (NullReferenceException excpt) {
XtraMessageBox.Show(excpt.Message);
}
}
private void ProcessFrame(object sender, EventArgs arg) {
Image<Bgr, Byte> frame = _capture.QueryFrame();
ImageBoxCapture.Image = frame;
}
private void CharmsBarBase_ButtonTop01Click(object sender, EventArgs e) {
InitCapture(0);
}
private void CharmsBarBase_ButtonTop02Click(object sender, EventArgs e) {
InitCapture(1);
}
Regards.

Resources