How to make Transparent Web-browser control - c#

I have a system windows forms where i show the web browser control over the media-player control as shown in image below,
I want to make Transparent web browser control. I have try many things but i am not able to make transparency over web browser control, i have try :
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.FromArgb(0, 0, 0, 0);
this.TransparencyKey = Color.Red;
this.BackColor = Color.Magenta;
this.TransparencyKey = Color.Magenta;*/
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;
My code is :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.DirectX.AudioVideoPlayback;
using System.Windows.Forms;
namespace Windows_Video
{
public partial class Form1 : Form
{
Video vdo;
public string mode = "play";
public string PlayingPosition, Duration;
public Form1()
{
InitializeComponent();
// VolumeTrackBar.Value = 4;
}
private void Form1_Load(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.textBox1.Text = openFileDialog1.FileName;
}
axWindowsMediaPlayer1.URL = textBox1.Text;
axWindowsMediaPlayer1.Ctlcontrols.play();
}
private void button1_Click(object sender, EventArgs e)
{
/* OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.textBox1.Text = openFileDialog1.FileName;
}*/
}
private void button2_Click(object sender, EventArgs e)
{
// axWindowsMediaPlayer1.URL = textBox1.Text;
// axWindowsMediaPlayer1.Ctlcontrols.play();
}
private void button3_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//this.BackColor = System.Drawing.Color.Transparent;
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;
}
}
}

you have to make another form with a web browser control set the opacity 50% in the form properties and then call on button or by some other method it will be work:
private void button1_Click(object sender, EventArgs e)
{
Form2 min = new Form2();
min.Show();
}
By this technique u can set the opacity over web browser control/full form

Related

Closing form5 from form1 if download completed

Here is the whole code from form1 :
using System;
using System.IO;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.IO.Compression;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Diagnostics.Tracing;
namespace BSCS_Launcher
{
public partial class Form1 : Form
{
private WebClient webClient = null;
const string basPath = #"cstrike";
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Form6 f6 = new Form6();
f6.ShowDialog(); // Shows Form6 - Launchoptions
}
private void button1_Click(object sender, EventArgs e)
{
string path = #"steamlop.lop";
string cfgpath = #"cstrike/config.cfg";
FileAttributes attributes = File.GetAttributes(cfgpath);
if (File.Exists(path))
{
File.SetAttributes(cfgpath, File.GetAttributes(cfgpath) | FileAttributes.ReadOnly);
var str = File.ReadAllText(path);
System.Diagnostics.Process.Start("hl.exe", arguments: str);
}
else
{
string message = "Launch options not found. Please go into launch options and click double click Reset!!!";
string title = "Launch options error";
MessageBox.Show(message, title);
}
}
private void button3_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.ShowDialog(); // Shows Form2 - Features
}
private void button4_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.ShowDialog(); // Shows Form3 - Options
}
private void button5_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://fastxhoster.com/");
}
private void button7_Click(object sender, EventArgs e)
{
Form5 f5 = new Form5();
f5.ShowDialog(); // Shows Form5 - Updatelauncher
// Is file downloading yet?
if (webClient != null)
{
return;
}
var dirdir = new DirectoryInfo($"{basPath}");
if (!dirdir.Exists)
{
webClient = new WebClient();
webClient.DownloadFileCompleted += FileDownloading;
webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/verzija.php"), $"{basPath}/version.php");
}
else
{
webClient = new WebClient();
webClient.DownloadFileCompleted += FileDownloading;
webClient.DownloadFileAsync(new Uri("https://sipi-portfolio.000webhostapp.com/verzija.php"), $"{basPath}/version.php");
} //Ovaj kod treba da se izvrsi tek kada je igracu skinut novi update ukoliko ga je bilo
}
private void FileDownloading(object sender, AsyncCompletedEventArgs e)
{
webClient = null;
string pathfile = $"{basPath}/verzija.php";
string pathfile2 = $"{basPath}/version.php";
var str = File.ReadAllText(pathfile);
var str2 = File.ReadAllText(pathfile2);
if (str != str2)
{
CloseProcessing();
string message = "We found an avilable update for this launcher!";
string title = "Update launcher";
MessageBox.Show(message, title);
}
else
{
CloseProcessing();
string message = "No new updates!";
string title = "Update launcher";
MessageBox.Show(message, title);
}
}
public void CloseProcessing()
{
Form5 f5 = new Form5();
f5.Close(); // Closes Form5 - Updatelauncher
}
}
}
Here you can see that I created code for download one file from one website, and it should check if those 2 files have the same context, if not it should do something and if yes it should do something again, in both situations, it should close form5, but it not closing... I tried many codes to resolve this but it not affects...
Thanks in advance...!
just Declare Form5 outside of methods (in the class) and for closing it don't rredefine it:
private void button7_Click(object sender, EventArgs e)
{
Form5 f5 = new Form5();
f5.ShowDialog(); // Shows Form5 - Updatelauncher
to
Form5 f5 = new Form5();
private void button7_Click(object sender, EventArgs e)
{
f5.ShowDialog(); // Shows Form5 - Updatelauncher
and
public void CloseProcessing()
{
//remove this line: //Form5 f5 = new Form5();
f5.Close(); // Closes Form5 - Updatelauncher
}
when you call Form5 f5 = new Form5(); in CloseProcessing you create a new instance of form5 instead of closing existing one.

How To Save Background Image On Form Close In C#

I am making a desktop app in c# in which when the user selects specific name of background from the menu strip, then the background shall turn to that required background. The problem is that i cannot save the user input, i tried settings but i cannot find "system.drawing.image" in settings so is there any way i can save the user changed background ? No external backgrounds a user is allowed to change, just the ones in the resource folder. Here is my code which shows error that system.drawing.color cannot take place of drawing.image.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TAC
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
panel1.Location = new Point(165, 157);
panel2.Location = new Point(289, 158);
panel3.Location = new Point(47, 275);
panel4.Location = new Point(47, 402);
this.BackgroundImage = Properties.Settings.Default.FormImage;
}
private void bLUEToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackgroundImage = TAC.Properties.Resources.tex1;
}
private void gREENToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackgroundImage = TAC.Properties.Resources.tex2;
}
private void oRANGEToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackgroundImage = TAC.Properties.Resources.tex3;
}
private void rEDToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackgroundImage = TAC.Properties.Resources.tex4;
}
private void pURPLEToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackgroundImage = TAC.Properties.Resources.tex5;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.FormImage = this.BackgroundImage;
}
}
}
Use Save method to save settings
Properties.Settings.Default.Save();
If you want add an image to settings :
Add new setting with type string and use like this:
Save an image to setting ( when you close form)
MemoryStream ms = new MemoryStream();
Propertis.Resources.MyImage.Save(ms,ImageFormat.Jpeg);
Properties.Settings.Default.BackImg = Convert.ToBase64String(ms.ToArray());
Properties.Settings.Default.Save();
And read image from setting and set to background(in form load)
string img = Properties.Settings.Default.BackImg ;
byte[] i = Convert.FromBase64String(img);
this.BackgroundImage = Image.FromStream(new MemoryStream(i));
How add custom settings ?
http://www.codeproject.com/Articles/29130/Windows-Forms-Creating-and-Persisting-Custom-User

How can i print a listbox list in c# windows form app?

I'm currently having issues with my code in terms of getting a printing option to show up when thy click a specific button.
I am making a reminder program and was just experimenting. Also would like to know the most efficient way to add a daily notification system to my program
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Mail;
using System.IO;
using System.Drawing.Printing;
using System.Security;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
namespace simpleapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add("Reminder: " + textBox1.Text);
}
private void input_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
listBox1.Items.Add("Reminder: " + textBox1.Text );
}
}
private void button2_Click(object sender, EventArgs e)
{
for (int rmd = listBox1.SelectedIndices.Count - 1; rmd >= 0; rmd--)
{
listBox1.Items.RemoveAt(listBox1.SelectedIndices[rmd]);
}
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.SelectionMode = SelectionMode.MultiExtended;
}
private void button6_Click(object sender, EventArgs e)
{
FAQ faqs = new FAQ();
faqs.Show();
}
// When the Button is Clicked the List is saved in a ".txt file format for the user to view later
private void button3_Click(object sender, EventArgs e)
{
var Savingfileas = new SaveFileDialog();
Savingfileas.Filter = "Text (*.txt)|*.txt ";
if (Savingfileas.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
using (var Reminder = new StreamWriter(Savingfileas.FileName, false))
foreach (var item in listBox1.Items)
Reminder.Write(item.ToString() + Environment.NewLine);
MessageBox.Show("File has been successfully saved"+ '\n' + "Thank you for using the Remindr program");
}
}
private void button4_Click(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
Email_Client emc = new Email_Client();
emc.Show();
}
}
}
You have a few options. One is to graphically layout a print document and iterate through your listbox while drawing the text in the textbox using x and y coordinates. A better way would be to get your listbox items into a dataset and use it to generate a report. Are you storing these items in a database for retrieval? Here's a link that should help you get started. The tutorial is in VB.Net but there's only a small amount of code to this and should be easy to repeat using C# code.
Here is an absolutely minimal example of printing a ListBox.
It assumes your ListBox contains strings and shows a PrintPreviewDialog; it sets the page unit to mm, do pick a unit you are comfortable with..!
Of course you may chose one or more different fonts etc..
private PrintDocument document = new PrintDocument();
private void printButton_Click(object sender, EventArgs e)
{
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = document;
ppd.Document.DocumentName = "TESTING";
document.PrintPage += document_PrintPage;
ppd.ShowDialog();
}
void document_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
int leading = 5;
int leftMargin = 25;
int topMargin = 10;
// a few simple formatting options..
StringFormat FmtRight = new StringFormat() { Alignment = StringAlignment.Far};
StringFormat FmtLeft = new StringFormat() { Alignment = StringAlignment.Near};
StringFormat FmtCenter = new StringFormat() { Alignment = StringAlignment.Near};
StringFormat fmt = FmtRight;
using (Font font = new Font( "Arial Narrow", 12f))
{
SizeF sz = e.Graphics.MeasureString("_|", Font);
float h = sz.Height + leading;
for (int i = 0; i < listBox1.Items.Count; i++)
e.Graphics.DrawString(listBox1.Items[i].ToString(), font , Brushes.Black,
leftMargin, topMargin + h * i, fmt);
}
}
The actual printing is triggered when the user clicks the printer symbol in the dialog.
Note that there are more StringFormat options!

Change file attribute pragmatically

im kinda new to programming and As university project,i have to write a program which changes a file info like a virus and then undo the changes just like anti virus.
i wrote the code for changing attribute on read only,But what about Hidden or system file ?
and what is the way for undoing it !
where im going wrong in coding ??
Here is my main form code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OpenFileDialog fDialog;
void button1_Click(object sender, EventArgs e) // Browse button
{
fDialog = new OpenFileDialog();
fDialog.Title = "Open a Text File";
fDialog.Filter = "TXT Files|*.txt|doc Files|*.doc";
fDialog.InitialDirectory = #"C:\";
if (fDialog.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(fDialog.FileName.ToString());
}
textBox1.Text = fDialog.FileName;
fDialog.AddExtension = true;
fDialog.CheckFileExists = true;
fDialog.CheckPathExists = true;
}
private void textBox1_TextChanged(object sender, EventArgs e)//the path showing text box
{
}
private void button2_Click(object sender, EventArgs e)//read-only button
{
fDialog.ReadOnlyChecked = true;
}
private void button3_Click(object sender, EventArgs e) //Hidden button
{
}
}
}

C# SERIAL PORT TEXTBOX ISSUE

I want to create a form having button,textbox,serialport in Visual c# 2010. My objective is when a button is pressed the data coming from the serial port has to displayed in textbox. I copied the following code from a tutorial. The textbox is not showing anything. Here's is the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ser1
{
public partial class Form1 : Form
{
private string RxString;
public Form1()
{
InitializeComponent();
}
private void buttonStart_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM4";
serialPort1.BaudRate = 9600;
serialPort1.Open();
if (serialPort1.IsOpen)
{
buttonStart.Enabled = false;
buttonStop.Enabled = true;
textBox1.ReadOnly = false;
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// If the port is closed, don't try to send a character.
if (!serialPort1.IsOpen) return;
// If the port is Open, declare a char[] array with one element.
char[] buff = new char[1];
// Load element 0 with the key character.
buff[0] = e.KeyChar;
// Send the one character buffer.
serialPort1.Write(buff, 0, 1);
// Set the KeyPress event as handled so the character won't
// display locally. If you want it to display, omit the next line.
e.Handled = true;
}
private void DisplayText(object sender, EventArgs e)
{
textBox1.Text=RxString.Trim();
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
RxString = serialPort1.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}
private void buttonStop_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
buttonStart.Enabled = true;
buttonStop.Enabled = false;
textBox1.ReadOnly = true;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (serialPort1.IsOpen) serialPort1.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}'

Categories

Resources