|
tjeffries wrote: We have a DRM encripted WMV file, and we need to control the size of the activation window that comes up while the license is being verified. I've seen files that do this, but we haven't been able to find a way. Apparently this is set by Windows Media Player. How do we tell WMP what size window we want?
You could try using the WinAPI, using FindWindow and SendMessage to set the appropriate size.
I are Troll
|
|
|
|
|
The following code is meant to draw a grid and is a custom control (one that can be dragged from the toolbox)
:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
AutoScroll = true;
}
Point _rowColumn;
Point _widthHeight;
Rectangle[,] _bound;
public void Init(int x, int y, int width, int height)
{
SetAutoSizeMode(AutoSizeMode.GrowAndShrink);
_rowColumn = new Point(x, y);
_bound = new Rectangle[x, y];
_widthHeight = new Point(width, height);
_drawArea = new Bitmap(Width, Height);
LoadTiles();
_loaded = true;
AutoScrollMinSize = new Size(x * width, y * height);
}
void LoadTiles()
{
for (int x = 0; x < _rowColumn.X; x++)
{
for (int y = 0; y < _rowColumn.Y; y++)
{
_bound[x, y] = new Rectangle(x* _widthHeight.X, y*_widthHeight.Y, _widthHeight.X, _widthHeight.Y);
}
}
}
Bitmap _drawArea;
bool _loaded = false;
void DrawGrid()
{
Graphics gfx = Graphics.FromImage(_drawArea);
gfx.Clear(Color.White);
Pen pen = new Pen(Color.Black,1);
foreach (Rectangle r in _bound)
{
gfx.DrawRectangle(pen, r);
}
gfx.Dispose();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.Clear(Color.White);
Matrix mx = new Matrix(1, 0, 0, 1, AutoScrollPosition.X, AutoScrollPosition.Y);
e.Graphics.Transform = mx;
e.Graphics.PageUnit = GraphicsUnit.Pixel;
if (!_loaded) return;
DrawGrid();
Graphics gfx = e.Graphics;
gfx.DrawImage(_drawArea, -AutoScrollPosition.X, -AutoScrollPosition.Y, _drawArea.Width, _drawArea.Height);
gfx.Dispose();
}
private void UserControl1_Paint(object sender, PaintEventArgs e)
{
}
}
It displays everything but for some reason when I scroll the lines distort!
Here is a link of what it looks like without scrolling (what I would like it to look like)
http://img130.imageshack.us/i/should.png/
Here is a link to what it looks like when scrolled:
http://img139.imageshack.us/i/isnt.png/[^]
The control has no embedded stuff (ie the auto scroll is applied directly to the blank box that appears by default when creating a new control).
Thanks !
|
|
|
|
|
Hi again,
the problem with AutoScroll is Windows, while scrolling, will copy and move that part of the painting that it can reuse, and order your Paint handler to only paint the new stuff, the part that becomes visible by scrolling. And that interferes with your intentions.
Furthermore, your code is much too complex; you are using an image, there is no need for, nor advantage in, doing that. Here is a simple example that works well; I use a specialized panel to get double-buffering, and I invalidate the (entire) panel when scrolling, forcing an all-paint, no-copy approach.
Panel p;
int nHor=40;
int nVert=10;
int wid=20;
int hei=20;
public void Demo() {
Form f=new Form();
f.Bounds=new Rectangle(0, 0, 500, 500);
p=new UserDrawnPanel();
p.Bounds=new Rectangle(20, 20, 400, 400);
p.AutoScroll=true;
p.AutoScrollMinSize=new Size(nHor*wid+10, nVert*hei+10);
p.BackColor=Color.White;
p.Paint+=new PaintEventHandler(p_Paint);
p.Scroll+=new ScrollEventHandler(p_Scroll);
f.Controls.Add(p);
f.Show();
}
void p_Scroll(object sender, ScrollEventArgs e) {
log("Scroll="+e.NewValue);
p.Invalidate();
}
void p_Paint(object sender, PaintEventArgs e) {
Graphics g=e.Graphics;
log("ClipRectangle="+e.ClipRectangle);
log("AutoScrollPosition="+p.AutoScrollPosition);
g.TranslateTransform(p.AutoScrollPosition.X, p.AutoScrollPosition.Y);
for (int y=0; y<=nVert; y++) g.DrawLine(Pens.Black, 0, y*hei, nHor*wid, y*hei);
for (int x=0; x<=nHor ; x++) g.DrawLine(Pens.Black, x*wid, 0, x*wid, nVert*hei);
}
class UserDrawnPanel : Panel {
public UserDrawnPanel() {
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
}
BTW: you can safely ignore the log statements.
|
|
|
|
|
Thanks again it works well
|
|
|
|
|
you're welcome.
|
|
|
|
|
hi all, How to create xmpp client using C#? I want to develop an application that will chat with xmpp server like jabber etc?
it's manjeet!
|
|
|
|
|
choose a single forum to ask your question, and stick to it.
|
|
|
|
|
Personally I think using smiley's randomly is just damn annoying.
Anyway this may be of use, http://tinyurl.com/28nfze4[^]
Programming is 10% science, 20% ingenuity, and 70% getting the ingenuity to work with the science.
WYSIWYMGIYRRLAAGW: What You See Is What You Might Get If You’re Really Really Lucky And All Goes Well.
|
|
|
|
|
Hi,
I am trying to prevent users from resizing the form window. I have set:
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.ControlBox = false;
It prevents user from resizing except that if I doouble-click on the title bar on top, it resizes. Is there a way to prevent this as well?
Thanks.
|
|
|
|
|
Hi,
if you were to have
if (WindowState==FormWindowState.Normal) WindowState = FormWindowState.Maximized;
within the Form's Resize handler, you probably would get what you want (a Form that is either Maximized or Minimized).
And I as a user would probably hate your app and remove it from my system right away.
I like an app to remember its window bounds and reuse the same value next time around, and not to dictate how I choose to use my system.
|
|
|
|
|
I understand it is not user friendly but it is not supposed to be. This is for a kiosk style app and it is the only app running and should always be in maximze state. I would also remove any app from my machine if it dictates how it should be alwyas be displayed.
|
|
|
|
|
In case someone else has the same issue, this is how I solved it:
protected override void WndProc(ref System.Windows.Forms.Message message)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MOVE = 0xF010;
const int WM_NCDOUBLECLICK = 0x00A3;
switch(message.Msg)
{
case WM_SYSCOMMAND:
int command = message.WParam.ToInt32() & 0xfff0;
if (command == SC_MOVE)
return;
break;
// Non-client double click
case WM_NCDOUBLECLICK:
return;
}
base.WndProc(ref message);
}
|
|
|
|
|
That may be both unnecessary and insufficient; if the application shows in the task bar, you can right click there and choose "Restore".
|
|
|
|
|
Thanks Luc. It is a kiosk app and I am actually in the process of finding some way to clamp down on what users can do (disable CTL-ALT-DEL, ALT-TAB, etc., remove task bar, ...)
In case anyone knows how to accomplish these, i would really appreciate a sample or pointing me to right direction.
|
|
|
|
|
You should have said so right away. I have no experience with kiosk mode, but the topic pops up regularly around here; the best reply seems to be this one[^]. For more, use CodeProject's message search facility, or Google.
|
|
|
|
|
I would like to have the grid automatically add a new row when the user presses "Tab" from the last cell in the last row of the grid.
I have set AllowUserAddRows property to "false"
Thanks,
Sri
|
|
|
|
|
I think this should be simple. You need to capture the KeyPreview on dgv, check if there is a cell selected, then if it is the last cell,last row and then add a new column. Then set the selection to the first cell of the new row.
|
|
|
|
|
i need help on usb drive. when a user inserts a usb drive, auto run starts and diplays some of the options to select from. what i want is to add my applications exe to the list of auto run when usb drive is inserted in usb port, so that i can select my application and do some aftermath. please help. simply i want usb drive to run my application when i insert it into my computer.
|
|
|
|
|
you should pick one forum to ask your question.
|
|
|
|
|
I am new to making custom windows forms control's and created a small component that can draw a grid.
The problem I am facing is when I scroll using the panels auto scroll features it seems to flicker and be displaced but what I am hoping for is a smooth transition across the x or y axis.
using System.Drawing;
using System.Windows.Forms;
namespace TileMapper.Presentation.Controls
{
public partial class MapRenderer : UserControl
{
private Point _tileBound;
private Point _rowsColumns;
private bool _initalized = false;
public MapRenderer()
{
InitializeComponent();
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();
}
public void InitalizeGrid(int tileWidth, int tileHeight, int rows, int columns)
{
_tileBound = new Point(tileWidth, tileHeight);
_rowsColumns = new Point(rows, columns);
panel1.AutoScrollMinSize = new Size(_tileBound.X * _rowsColumns.X, _tileBound.Y * _rowsColumns.Y);
_initalized = true;
_pen = new Pen(Color.Black);
_tile = new Rectangle(0, 0, _tileBound.X, _tileBound.Y);
}
Pen _pen;
Rectangle _tile;
void DrawGrid(Graphics e)
{
Image im = Image.FromFile(@"H:\My Pictures/tile.png");
for (int x = 0; x < _rowsColumns.X; x++)
{
for (int y = 0; y < _rowsColumns.Y; y++)
{
Rectangle rec = new Rectangle(x * _tileBound.X - panel1.HorizontalScroll.Value
, y * _tileBound.Y-panel1.VerticalScroll.Value, _tileBound.X, _tileBound.Y);
e.DrawRectangle(_pen, rec);
e.DrawImage(im, rec, _tile, GraphicsUnit.Pixel);
}
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (_initalized) DrawGrid(e.Graphics);
}
}
}
The design code and such is literally all design and has no functionality and has no need to be here.
Sorry for the bad code but I have tried many double buffering techniques and such to fix this problem so its a bit hacked up
Anyone got some ideas to stop this flicker?
Thanks !
|
|
|
|
|
there are a few ways to reduce flickering, the most obvious one is to make your Paint handler cheaper, i.e. consume less CPU cycles and fewer objects. In your case, here are some suggestions:
1.
there seems to be an image file that gets loaded and decoded each and every time; I suggest you store that image as a class member and load it only once.
2.
you are calling panel1.HorizontalScroll.Value and panel1.VerticalScroll.Value over and over; you'd better store those in a couple of local variables (ADDED: within your Paint handler of course).
So try these, then re-evaluate the situation.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
modified on Wednesday, June 9, 2010 3:51 PM
|
|
|
|
|
I done what you recommended but it still flickers allot and its only 1000 tiles at 32*32 width and height !
Updated Code:
using System.Drawing;
using System.Windows.Forms;
namespace TileMapper.Presentation.Controls
{
public partial class MapRenderer : UserControl
{
private Point _tileBound;
private Point _rowsColumns;
private bool _initalized = false;
public MapRenderer()
{
InitializeComponent();
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();
}
public void InitalizeGrid(int tileWidth, int tileHeight, int rows, int columns)
{
_tileBound = new Point(tileWidth, tileHeight);
_rowsColumns = new Point(rows, columns);
panel1.AutoScrollMinSize = new Size(_tileBound.X * _rowsColumns.X, _tileBound.Y * _rowsColumns.Y);
_initalized = true;
_pen = new Pen(Color.Black);
_tile = new Rectangle(0, 0, _tileBound.X, _tileBound.Y);
_im = Image.FromFile(@"C:/box.png");
_scrollValue = new Point(panel1.HorizontalScroll.Value, panel1.VerticalScroll.Value);
}
private Point _scrollValue;
Pen _pen;
Rectangle _tile;
private Image _im;
void DrawGrid(Graphics e)
{
for (int x = 0; x < _rowsColumns.X; x++)
{
for (int y = 0; y < _rowsColumns.Y; y++)
{
Rectangle rec = new Rectangle(x * _tileBound.X - _scrollValue.X
, y * _tileBound.Y - _scrollValue.Y, _tileBound.X, _tileBound.Y);
e.DrawImage(_im, rec, _tile, GraphicsUnit.Pixel);
}
}
}
private void panel1_Paint_1(object sender, PaintEventArgs e)
{
if (_initalized)
{
_scrollValue.X = panel1.HorizontalScroll.Value;
_scrollValue.Y = panel1.VerticalScroll.Value;
DrawGrid(e.Graphics);
}
}
}
}
|
|
|
|
|
I'm not absolutely sure, but I have the impression that you are trying to create a virtual panel (a big one scrolling inside a smaller one), maybe 32000 * 32000 pixels large, of which only a small part is visible (I can't see the value of _rowsColumns).
Now painting 1 billion pixels when only say 1 million are visible is a huge waste. I can only hope that the PaintEventArgs holds something (maybe ClipRectangle, maybe some member of Graphics) that will enable you to skip most iterations of your nested for loops.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thanks for that I think I have solved the looping (not looping through everything) but now a new problem arises, i have to refresh the control every time I scroll to see the updated grid !
using System.Drawing;
using System.Windows.Forms;
namespace TileMapper.Presentation.Controls
{
public partial class MapRenderer : UserControl
{
private Point _tileBound;
private Point _rowsColumns;
private bool _initalized = false;
Rectangle[,] _renderBounds;
public MapRenderer()
{
InitializeComponent();
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();
}
public void InitalizeGrid(int tileWidth, int tileHeight, int rows, int columns)
{
_tileBound = new Point(tileWidth, tileHeight);
_rowsColumns = new Point(rows, columns);
panel1.AutoScrollMinSize = new Size(_tileBound.X * _rowsColumns.X, _tileBound.Y * _rowsColumns.Y);
_initalized = true;
_pen = new Pen(Color.Black);
_tile = new Rectangle(0, 0, _tileBound.X, _tileBound.Y);
_im = Image.FromFile(@"D:/tile.png");
_scrollValue = new Point(panel1.HorizontalScroll.Value, panel1.VerticalScroll.Value);
_renderBounds = new Rectangle[_tileBound.X, _tileBound.Y];
for (int x = 0; x < _tileBound.X; x++)
{
for (int y = 0; y < _tileBound.Y; y++)
{
_renderBounds[x,y] = new Rectangle(x * _tileBound.X
, y * _tileBound.Y, _tileBound.X, _tileBound.Y);
}
}
}
private Point _scrollValue;
Pen _pen;
Rectangle _tile;
private Image _im;
void DrawGrid(Graphics e, Rectangle bound)
{
int start = bound.X / _tileBound.X;
int end = bound.X/_tileBound.X + bound.Width/_tileBound.X;
int startY = bound.Y / _tileBound.Y;
int endY = bound.Y + bound.Height/_tileBound.Y;
for (int x = start; x < end; x++)
{
for (int y = startY; y < endY; y++)
{
e.DrawImage(_im, _renderBounds[x,y], _tile, GraphicsUnit.Pixel);
}
}
}
private void panel1_Paint_1(object sender, PaintEventArgs e)
{
if (_initalized)
{
Rectangle a = e.ClipRectangle;
_scrollValue.X = panel1.HorizontalScroll.Value;
_scrollValue.Y = panel1.VerticalScroll.Value;
DrawGrid(e.Graphics, a);
}
}
private void panel1_Scroll(object sender, ScrollEventArgs e)
{
panel1.Refresh();
}
}
}
|
|
|
|
|
I take it flickering is acceptable now?
yes you now must paint while scrolling; I'd guess a panel1.Invalidate() should do it, Refresh() would be more expensive as it waits for the repaint to finish IIRC.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|