I got a problem with white space surrounding the video, I've added margin: 0 which fixed the top white space. But now I still got white space on other positions. I also tried to resize the browser control to match the iframe. But when I resize, the same thing happends:
var embed = "<html><head>" +
"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge,chrome=1\"/>" +
"</head><body style=\"margin: 0\">" +
"<iframe width=\"560\" height=\"315\" src=\"{0}\"" +
"frameborder=\"1\" allow =\"autoplay; encrypted-media\" ></iframe>" +
"</body></html>";
var url = "https://www.youtube.com/embed/JvSZKB2WNKg?rel=0&showinfo=0";
webBrowser1.DocumentText = string.Format(embed, url);
You need to:
Set the size of the WebBrowser control same as the iframe
Turn off scrolling of body tag by setting scroll="no".
Turn off padding and margin for body tag, by setting style="padding:0px;margin:0px;".
Remove borders of iframe tag by setting style="border:0px;" for body.
So your code should be:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
int w = 560;
int h = 315;
this.webBrowser1.Width = w;
this.webBrowser1.Height = h;
var embed = "<html><head>" +
"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge,chrome=1\"/>" +
"</head><body scroll=\"no\" style=\"padding:0px;margin:0px;\">" +
"<iframe style=\"border: 0px;\" width=\"{1}\" height=\"{2}\" src=\"{0}\"" +
"allow =\"autoplay; encrypted-media\" ></iframe>" +
"</body></html>";
var url = "https://www.youtube.com/embed/JvSZKB2WNKg?rel=0&showinfo=0";
webBrowser1.DocumentText = string.Format(embed, url, w, h);
}
Related
I want to click a button which is at certain location (X,Y coordinate) inside a webbrowser control in windows form. But I am unable to find the correct location. The current coding shifts point somewhere else then the exact point.
private void Document_MouseUp(object sender, HtmlElementEventArgs e)
{
Point cp = this.PointToClient(Cursor.Position); // Getting a cursor's position according form's area
MessageBox.Show("Cursor position: X = " + cp.X + ", Y = " + cp.Y);
}
webBrowser1.Document.MouseUp += new HtmlElementEventHandler(Document_MouseUp);
Point ScreenCoord = new Point(815, 192); //This value is returned by Document_MouseUp
//Point BrowserCoord = webBrowser1.PointToClient(ScreenCoord);
HtmlElement elem = webBrowser1.Document.GetElementFromPoint(ScreenCoord);
if (elem.InnerText.Equals("Something"))
{
elem.InvokeMember("Click");
}
I have the following problem with ListbBox.
To make it easy to understand I have simplified it a bit.
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("xxxxxx" +"\t\t\t"+ "yyyyyyy");
listBox1.Items.Add("xxxxxxx" + "\t\t\t" + "yyyyyyy");
listBox1.Items.Add("xxxxxxxx" + "\t\t\t" + "yyyyyyy");
listBox1.Items.Add("xxxxxxxxx" + "\t\t\t" + "yyyyyyy");
listBox1.Items.Add("xxxxxxxxxx" + "\t\t\t" + "yyyyyyy");
}
}
From row 1 to 4 it prints out perfectly in straight rows downwards. But the 5th row is completly off when I run the program, although there is plenty of space. Can any body help me to get all items to be in straight rows downwards?
You need to set the property CustomTabOffsets and the property UseCustomTabOffsets and then you can reduce the number of tabs in your strings to only one.
For example
ListBox lb = new ListBox();
lb.Size = new Size(500, 200);
lb.CustomTabOffsets.Add(100);
lb.UseCustomTabOffsets = true;
lb.Items.Add("xxxxxx" + "\t" + "yyyyyyy");
lb.Items.Add("xxxxxxx" + "\t" + "yyyyyyy");
lb.Items.Add("xxxxxxxx" + "\t" + "yyyyyyy");
lb.Items.Add("xxxxxxxxx" + "\t" + "yyyyyyy");
lb.Items.Add("xxxxxxxxxx" + "\t" + "yyyyyyy");
Form f = new Form();
f.Controls.Add(lb);
f.Show();
Of course you should change that 100 to something more consistent with the actual maximum length of the first part of your strings and the width of your ListBox
The standard ListBox supports Tab Stops (it's created using the LBS_USETABSTOPS style), but custom Tab Stop must be enabled setting UseCustomTabOffsets= true, then adding one or more values, representing the Tab positions, to the CustomTabOffsets IntegerCollection.
There's a catch in calculating these positions; as described in Docs about the LB_SETTABSTOPS message:
(...) the integers represent the number of quarters of the average character
width for the font that is selected into the list box. For example, a
tab stop of 4 is placed at 1.0 character units, and a tab stop of 6 is
placed at 1.5 average character units. However, if the list box is
part of a dialog box, the integers are in dialog template units. The
tab stops must be sorted in ascending order (...)
Since Font.ToLogFont() doesn't return the average size of a character in the lfWidth member of the LOGFONT structure, we can calculate it (without PInvoking) from pixels measures as:
([CurrentTextWidth] / [AverageCharWidth]) * [TabSize]
Where [CurrentTextWidth] is the width in pixels of a string, calculated using TextRenderer.MeasureText,
the [AverageCharWidth] can be calculated measuring the difference between M and i,
and [TabSize] represent the quarters of the average char width (as described in the Docs, a TabStop of 4 is equal to the width of the average char, in relation to the Font currently selected).
Sample test, to create 3 columns from text parts separated by '\t' in a ListBox:
listBox1.Items.AddRange(new[] {
"x\tyyyyyyy\teeeeee",
"xxxx\tyyyyyyy\tmmmmmmm",
"xxxxxx\tyyyyyyy\tlllllll",
"AbcdEfgHilm\tyyyyyyy\tgggggggg",
"xxxxxx\tyyyyyyy\tzzzzzzz",
"XXaaMMiixxx\tyyyyyyy\tiiiiiiiiiiiiiiii"
});
SetListBoxTabs(listBox1);
Here, I'm setting float tabSize = 4.2f instead of 4.0, because there must be some space between the text parts separated by a Tab, so I'm adding a fraction of the base value to create some space between Columns.
This value can then be used to proportionally adjust the space between columns.
public void SetListBoxTabs(ListBox listBox)
{
float tabSize = 4.2f;
float currTabStop = 0;
int tabs = listBox.GetItemText(listBox.Items[0]).Split('\t').Length - 1;
if (tabs == 0) return;
var tabStops = new List<int>(tabs);
tabStops.AddRange(Enumerable.Repeat(0, tabs).ToArray());
using (var g = Graphics.FromHwnd(listBox.Handle))
{
float average = GetFontAverageCharSize(g, listBox.Font);
foreach (var item in listBox.Items)
{
string text = listBox.GetItemText(item);
string[] parts = text.Split('\t'); // Use Substring(IndexOf()) here
for (int i = 0; i < parts.Length - 1; i++)
{
float width = TextRenderer.MeasureText(g, parts[i], listBox.Font,
Size.Empty, TextFormatFlags.LeftAndRightPadding).Width;
float tabWidth = (width / average) * tabSize;
currTabStop += tabWidth;
tabStops[i] = (int)Math.Max(currTabStop, tabStops[i]);
}
currTabStop = 0;
}
}
listBox.UseTabStops = true; // Just in case 1 ...
listBox.UseCustomTabOffsets = true;
var offsets = listBox.CustomTabOffsets;
offsets.Clear(); // Just in case 2 ...
foreach (int tab in tabStops) { offsets.Add(tab); }
}
public float GetFontAverageCharSize(Graphics g, Font font)
{
string textMax = new string('M', 100);
string textMin = new string('i', 100);
float maxWidth = TextRenderer.MeasureText(g, textMax, listBox1.Font).Width;
float minWidth = TextRenderer.MeasureText(g, textMin, listBox1.Font).Width;
return (maxWidth + minWidth) / (2.0f * textMax.Length);
}
I am trying to make each line of text on a WPF textblock display in a different color. I have the following code which makes the entire block's font color purple because that's the last color it's set to. How can I make it so each potion is displayed in a different color?
private void btnShowPotions_Click(object sender, RoutedEventArgs e) {
tbPotionInfo.Foreground = Brushes.Green;
tbPotionInfo.Text = smallPotion.Name + "(" + smallPotion.AffectValue + ")\r\n";
tbPotionInfo.Foreground = Brushes.Blue;
tbPotionInfo.Text += mediumPotion.Name + "(" + mediumPotion.AffectValue + ")\r\n";
tbPotionInfo.Foreground = Brushes.Red;
tbPotionInfo.Text += largePotion.Name + "(" + largePotion.AffectValue + ")\r\n";
tbPotionInfo.Foreground = Brushes.Purple;
tbPotionInfo.Text += extremePotion.Name + "(" + extremePotion.AffectValue + ")\r\n";
}
You can make use of Run.
Here is the sample of how to use the Run
Run run = new Run(smallPotion.Name + "(" + smallPotion.AffectValue + ")\r\n");
run.Foreground = Brushes.Green;
tbPotionInfo.Inlines.Add(run);
run = new Run(mediumPotion.Name + "(" + mediumPotion.AffectValue + ")\r\n");
run.Foreground = Brushes.Blue;
tbPotionInfo.Inlines.Add(run);
...
Haven't verified but I hope it will help you.
Use textblock like this
<TextBlock>
<TextBlock Name="tbSmallPotion" Foreground="Green"/
<TextBlock Text="tbMediumPotion"Foreground="Blue"/>
</TextBlock>
and set the values
tbSmallPotion.Text = smallPotion.Name + "(" + smallPotion.AffectValue + ")\r\n";
tbMediumPotion.Text = mediumPotion.Name + "(" + mediumPotion.AffectValue + ")\r\n";
What's the deal, i have an imagePanel (u can look at it as a picturePanel)
called imagePanel1 (i imported it so i don't have to make scroll Bars :))
and i have a treeView on the left side, from witch i can drag a node, and drop it over the imagePanel, where i get a Location of the drop, and on that location i create a normal panel called panel1
And so i do 100 times, so at the end i ll have an imagePanel full of small panels...
Now is the problem, when i click on the imagePanel (where a panel is located)
I want that panel to be selected on MousePress, and moved on mouseMove, and eventualLy deleted on a btnDelete...
Here is the code for the imagePanel:
//***********************************************************************
private void imagePanel1_DragDrop_1(object sender, DragEventArgs e)
{
Type testTip = new TreeNode().GetType();
YLScsImage.ImagePanel dropPicturePanel = (YLScsImage.ImagePanel)sender;
TreeNode movedNode;
_mouseDownSelectedWindow = Rectangle.Empty;
if (e.Data.GetDataPresent(testtype))
{
movedNode= (TreeNode)e.Data.GetData(testType);
dropPicturePanel.Tag = movedNode.Tag;
movedNode.ImageIndex = 1;
movedNode.SelectedImageIndex = 1;
movedNode.ForeColor = Color.Gray;
//**************************************
//HERE IS THE CODE FOR THE CREATED PANEL
Panel panel1 = new Panel();
Point point1 = this.PointToClient(new Point(e.X - 278, e.Y - 19)); //the imagePanel1 is on the form at the point 278,19
panel1.AllowDrop = true;
panel1.Location = point1;
panel1.BackgroundImage = iltest.Images[0]; //nvm
panel1.Height = 16;
panel1.Width = 16;
imagePanel1.Controls.Add(panel1); //am adding it to the imagePanel1
//saving the locations of each panel
string path = #"C:\Users\Cosic\Desktop\ICR\TABELA3_Paneli.txt"; // path to file
if (!File.Exists(path))
File.Create(path);
if (panelBr == 0)
System.IO.File.WriteAllBytes(path, new byte[0]); //brise ceo text iz fajla
TextWriter sw = new StreamWriter(path, true);
sw.WriteLine(e.X + "; " + e.Y + "; " + panel1.Width + "; " + panel1.Height + ";");
sw.Close();
//am done with saving
panelBr++;//nvm
}
}
tell me if u need some more code...i got a lot of it ;)
and sorry for bad english, am not that good as I would like to be...
I solved the problem, like this:
panel1.MouseUp += new MouseEventHandler(panel1_MouseUp);
just write panel1.anyEventUWant += and 2 times tab button....
it generate automaticly a new function with a single code line in it
here is an example
void panel1_MouseUp (object sender, EventArgs e)
{
//throw new NotImplementedException();
}
U can access the panel like this: ((object)sender).
I created Div Over Image button css style postion is absolute
when i scroll the pages the div also scrolling down
how can i fix the dive over image button
#DamageDiv {
background-color:red;
position:absolute;
z-index:1000;/* heighest z-index show on top */
}
function DrawImage(e) {
var evt = e || window.event; // compliant with ie6
var posX = evt.clientX;
var posY = evt.clientY;
var iDiv = document.createElement('div');
iDiv.id = DamageType;
iDiv.style.top = posY + "px";
iDiv.style.left = posX + "px";
iDiv.style.width = "20px";
iDiv.style.height = "20px";
document.getElementsByTagName('body')[0].appendChild(iDiv);
}
Remove the position:absolute from your CSS - this makes the div stay in the same place on the screen when you scroll.
Read here:
Difference between style = "position:absolute" and style = "position:relative"