|
public partial class Form1 : Form
{
Rectangle r;
bool isDrawAllow = false;
int x = 0;
int y = 0;
List<PointEvent> events = new List<PointEvent>();
int lastTimeRecorded = 0;
Graphics g = null;
MouseHook mouseHook = new MouseHook();
public Form1()
{
InitializeComponent();
mouseHook.MouseMove += new MouseEventHandler(mouseHook_MouseMove);
mouseHook.MouseDown += new MouseEventHandler(mouseHook_MouseDown);
mouseHook.MouseUp += new MouseEventHandler(mouseHook_MouseUp);
r = new Rectangle(new Point(0,0), new Size(20, 20));
panel1.Invalidate();
}
void mouseHook_MouseUp(object sender, MouseEventArgs e)
{
events.Add(new PointEvent(e.X, e.Y));
}
void mouseHook_MouseDown(object sender, MouseEventArgs e)
{
events.Add(new PointEvent(e.X, e.Y));
}
void mouseHook_MouseMove(object sender, MouseEventArgs e)
{
events.Add(new PointEvent(e.X, e.Y));
}
private void button1_Click(object sender, EventArgs e)
{
events.Clear();
x = 0;
lastTimeRecorded = Environment.TickCount;
mouseHook.Start();
}
private void button2_Click(object sender, EventArgs e)
{
mouseHook.Stop();
}
private void PlayBack_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (isDrawAllow)
{
if (x < events.Count - 1)
{
PointEvent p = events[x];
r.Location = new Point(p.X, p.Y);
e.Graphics.FillRectangle(new SolidBrush(Color.Red), r);
}
e.Graphics.Dispose();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (x>= events.Count-2)
{
timer1.Stop();
}
isDrawAllow = true;
x++;
panel1.Invalidate();
}
}
here mouse hook is a third party lib.I'm using PointEvent class to store location(x,Y) in the list
yea this is drawing in the panel.
|
|
|
|
|
RectangleToClient
RectangleToScreen
|
|
|
|
|
coordinates (hence also mouse positions) are always relative to something. It could be the (top left corner of the) screen, it often is the containing Control. In your code, it is the Form half the time (see mouse events, they belong to the form), and the Panel the remaining times (see panel.Paint event). You need to fix that, probably by just compensating for the Panel's position relative to the Form.
There are many ways to do that. Maybe here the easiest is by applying a Graphics.TranslateTransform inside your paint handler.
|
|
|
|
|
I agree with Luc - but I would be tempted not to use the MouseHook lib at all (I've not heard of it, so I can't be sure you aren't using it for good reason). Instead, I would hook into the Panel MouseDown, MouseUp and MouseMove events which would give you coordinates relative to the panel rather than the form. It also only gives you mouse events when the mouse is over the panel - may be relevant!
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
tbResult.Text = string.Format("({0},{1})", e.X, e.Y);
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: I agree with Luc
You're too kind. I should have realized right away that translating coordinates from one Control to paint on another Control could not possibly be the right way to tackle the job. Of course, there is only one relevant Control (the one Panel), and no translation is involved.
|
|
|
|
|
Hi All,
i am trying to download a file from my website on my server, but i keep getting a error: Access to the path 'c:\ImageName.gif' is denied.
this is my code i am using:
<code>using (WebClient wcDownload = new WebClient())
{
try
{
webRequest = (HttpWebRequest)WebRequest.Create("http://www.XXXXXXXXXXX.XX.XX/Images/" + strImgName);
webRequest.Credentials = CredentialCache.DefaultCredentials;
webResponse = (HttpWebResponse)webRequest.GetResponse();
Int64 fileSize = webResponse.ContentLength;
strResponse = wcDownload.OpenRead("http://www.XXXXXXXXXXX.XX.XX/Images/" + strImgName);
string strFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
strLocal = new FileStream(strFolder + "\\" + strImgName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
int bytesSize = 0;
byte[] downBuffer = new byte[2048];
while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
strLocal.Write(downBuffer, 0, bytesSize);
}
string strAlert = "alert('" + strImgName + " downloaded to " + strFolder + "');";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", strAlert, true);
}
finally
{
strResponse.Close();
strLocal.Close();
}
}</code>
Any help is much appreciated.
living life on the flip side
|
|
|
|
|
Windows, since Vista, is rather picky on the locations it lets you create files. Have you tried a different path at all?
|
|
|
|
|
Are you trying to run this from your website? If so, you will probably find that Environment.SpecialFolder.DesktopDirectory doesn't return a value that you'd expect because the IIS user doesn't have a desktop.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi All,
thanks for the replies, i haven't tried a different path yet.
is there anyway i can get this download to work.
all i really need to do is allow the user to download the image from the website which is hosted on the server to their local machine, preferably their desktop.
living life on the flip side
|
|
|
|
|
Agweet wrote: i haven't tried a different path yet.
is there anyway i can get this download to work.
Isn't that a bit like going to the doctor and asking him to cure you but refusing to follow his advice?
/ravi
|
|
|
|
|
it may be OK to ask for advice, then not follow it. However asking again is a bit weird, yes.
|
|
|
|
|
Luc Pattyn wrote: it may be OK to ask for advice, then not follow it. However asking again is a bit weird, yes.
You've clearly not handled technical support calls from idiots non-technical users!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
well,
1. i am not an idiot, and that was not truly called for, but anyways,
2. i did however try a new path after i posted reply, no change, still get the error.
is it a permissions issue with the server accessing the local file? or is there something else i am missing?
living life on the flip side
|
|
|
|
|
Are you able to manually (i.e. thru the Windows UI) create a file with the same path name? That would help identify if it's a permissions issue.
/ravi
|
|
|
|
|
Just for grins, does this work any better?
WebClient wc = new WebClient();
wc.DownloadFile ("http://.../foo.jpg", @"C:\MyFolder\foo.jpg");
You may want to save the image to your user's application data path (to which you have write access).
/ravi
|
|
|
|
|
Hi Ravi,
thanks for the reply,
i tried downloading the file to the users application data but still get the error.
living life on the flip side
|
|
|
|
|
Is is possible that the target file has already been opened (for exclusive read or write), thereby preventing it from being overwritten? Although I think if that were the case you'd see a different exception.
/ravi
|
|
|
|
|
Agweet wrote: i am not an idiot, and that was not truly called for
I'm sorry - did I call you an idiot? If you look at the threads, I was talking to Luc, and making a generic comment about technical support phone calls. Trust me, if I wanted to insult you, you would know all about it!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: You've clearly not handled technical support calls from non-technical users!
I seem to find ways that ensure they don't come back...
|
|
|
|
|
Please oh great one! Tell me your secrets!
[edit]"oh", you clumsy typist Griff, "oh" - not "of"[/edit]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Sorry, I have no solution for you. Just a question: Why don't you use WebClient.DownloadFile for downloading the image?
Anyway, your code seems to be correct...
P.S. Have you heard about Path.Combine (because
+"\\" doesn't look so good)
|
|
|
|
|
Hi,
i have gridview and have Detail View.
I want to edit the page with all controls loaded instead of showing in Bound Field.
While using <asp:CommandField ShowEditButton="True" />
i am able to show all values in Text boxes.
Instead i need to show in respective controls like textbox,checkboxlist,listbox and drop down.How to implement this?
Any urls or links?
Guhananth.S
|
|
|
|
|
Please stop this now. You have become very annoying.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi,
i have gridview and have Detail View.
I want to edit the page with all controls loaded instead of showing in Bound Field.
While using <asp:CommandField ShowEditButton="True" />
i am able to show all values in Text boxes.
Instead i need to show in respective controls like textbox,checkboxlist,listbox and drop down.How to implement this?
Any urls or links?
<pre>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MenuList.aspx.cs" Inherits="MenuList" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td valign="top">
<asp:GridView ID="grd_MenuList" runat="server" AutoGenerateColumns="False"
onrowdatabound="grd_MenuList_RowDataBound" DataKeyNames="MenuId"
onselectedindexchanged="grd_MenuList_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="MenuId" HeaderText="MenuId" Visible="false" />
<asp:BoundField DataField="MenuName" HeaderText="MenuName"
SortExpression="MenuName" />
<asp:hyperlinkfield headertext="URL"
datatextfield="URL"
datanavigateurlfields="URL"
datanavigateurlformatstring="details_title.aspx?titleid={0}" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
<asp:TemplateField HeaderText="Role">
<ItemTemplate >
<asp:Label ID="lbl_Role" runat="server" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:HyperLink ID="hyp_Edit" runat="server" NavigateUrl='<%# Bind("MenuId") %>'
Text="Edit"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>--%>
<%-- <asp:CommandField HeaderText="Edit" ShowCancelButton="False"
ShowEditButton="True" ShowHeader="True" />--%>
<asp:CommandField ShowSelectButton="True" />
<%-- <asp:HyperLinkField HeaderText="Edit Details..." Text="Edit Details..." DataNavigateUrlFields="MenuId"
DataNavigateUrlFormatString="MenuCreation.aspx?ID={0}" /> --%>
</Columns>
</asp:GridView>
</td>
<td valign="top">
<asp:DetailsView AutoGenerateRows="False" DataKeyNames="MenuId" DataSourceID="SqlDataSource3"
HeaderText="Menu Details" ID="dtv_Menu" runat="server" Width="275px"
onitemupdated="dtv_Menu_ItemUpdated">
<Fields>
<asp:BoundField DataField="MenuName" HeaderText="MenuName"
SortExpression="MenuName" />
<asp:BoundField DataField="URL" HeaderText="URL" SortExpression="URL"/>
<asp:CheckBoxField DataField="ParentMenuId" HeaderText="Is Parent" />
<asp:BoundField DataField="ParentMenuId" HeaderText="ParentMenuId"
SortExpression="ParentMenuId" />
<asp:TemplateField>
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Order" HeaderText="Order" SortExpression="Order" />
<asp:BoundField DataField="RoleName" HeaderText="RoleName"
SortExpression="RoleName" />
<asp:BoundField DataField="Access" HeaderText="Access" SortExpression="Access" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:BoundField DataField="MenuId" HeaderText="MenuId" Visible="False"
ReadOnly="True" SortExpression="MenuId" />
<asp:CommandField ShowEditButton="True" />
<asp:HyperLinkField HeaderText="Edit Details..." Target="_top" Text="Edit Details..." DataNavigateUrlFields="MenuId"
DataNavigateUrlFormatString="MenuCreation.aspx?ID={0}" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:AZSSA_TestConnectionString %>"
SelectCommand="SELECT Menu.URL, Menu.ParentMenuId, Menu.MenuName, Menu.[Order], Menu.Status, Roles.RoleName, MenuRole.Access, Menu.MenuId FROM MenuRole INNER JOIN
Menu ON MenuRole.MenuId = Menu.MenuId INNER JOIN
Roles ON MenuRole.RoleId = Roles.RoleID
WHERE (Menu.MenuId = @MenuId)" >
<SelectParameters>
<asp:ControlParameter ControlID="grd_MenuList" Name="MenuId" PropertyName="SelectedValue"
Type="Int16"/>
</SelectParameters>
<%-- <UpdateParameters>
<asp:Parameter Name="au_lname" />
<asp:Parameter Name="au_fname" />
<asp:Parameter Name="phone" />
<asp:Parameter Name="address" />
<asp:Parameter Name="city" />
<asp:Parameter Name="state" Type="String" />
<asp:Parameter Name="zip" Type="String" />
<asp:Parameter Name="contract" />
<asp:Parameter Name="au_id" Type="String" />
</UpdateParameters>--%>
</asp:SqlDataSource>
</td>
</tr>
</table>
</pre>
<code>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Examples;
using System.Data;
using System.Data.SqlClient;
using System.Text;
public partial class MenuList : System.Web.UI.Page
{
public string strRoleName="";
protected void Page_Load(object sender, EventArgs e)
{
grd_MenuList.DataSource = SP.GetMenuList();
grd_MenuList.DataBind();
}
protected void grd_MenuList_SelectedIndexChanged(object sender, EventArgs e)
{
dtv_Menu.ChangeMode(DetailsViewMode.ReadOnly);
}
protected void dtv_Menu_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
grd_MenuList.DataBind();
}
</code>
Thanks
S.Guhananth
|
|
|
|
|
You are disregarding the forum guidelines in many ways and your question now is very unlikely to get any answers. Fix it! read the guidelines, and edit your message, do not start yet another one.
|
|
|
|