|
Hi
I found an issue in reading files.
My code is simple:
fFile = New System.IO.FileStream("somefile", IO.FileMode.Open, IO.FileAccess.Read)
where "somefile" is file, which is in use with another application.
When I try to execute this line I will get an error: "The process cannot access the file 'sometext' because it is being used by another process".
Notepad can open this file without problem, Wordpad can not.
Can someone explain me, how notepad reading files? Can I use this method of file reading in .NET VB, or WIN32 API ?
|
|
|
|
|
SOLVED:
fFile = New System.IO.FileStream(sFileName, IO.FileMode.Open, IO.FileAccess.Read, FileShare.ReadWrite)
FileShare.ReadWrite means I allow write access to application which is using file.
|
|
|
|
|
Hi,
I want to execute mousehover event when user pressed left mouse buttion and drag on labels.
I have added 30 labels programatically and i want to change backcolor of labels when user clicks on particular label or user click on label and drag in other labels with left buttion pressed.
Ex.: Sinerio like when we select mutiple files in explore, we pressed left buttion and drag on files they get selected.
Main problem is when we pressed left key and drag on other labels then mouseover or other evnts are not executed i.e. main problem.
Without pressed mouse left button mouseover or other events are executed. how to execute events when left buttion is pressed and drag on other labels.
Thanks
Sanjay
|
|
|
|
|
hi
how I can use / insted of . for decimal number in textbox and datagridview?
|
|
|
|
|
Simple.
If the number is 123.4 , simply type 123/4 . Problem solved.
Perhaps, if you explain what it is that you are trying to do (i.e. why you need to do this, and what you want to do with the data) it might make it easier for people to give a sensible answer.
[Edit]
Fixed a typo
[/Edit]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
modified on Wednesday, October 28, 2009 10:39 AM
|
|
|
|
|
Hi,
have a look at the NumberFormatInfo type. You probably want to set NumberFormatInfo.NumberDecimalSeparator and use the NFI in all relevant numeric input (Parse/TryParse) and output (ToString).
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Dear developpers,
I want help i want the source code in vb.net 2005 for paint programm
this program just like or similar to the paint application which come with windows
I need it the quickly if possible don't be late for me .
best wiches
|
|
|
|
|
Demanding code is not acceptable here
only two letters away from being an asset
|
|
|
|
|
In which case, get your money out and head for rentacoder or some similar site.
jamalhamou wrote: I need it the quickly if possible don't be late for me .
Depends on how much you pay - but beware, rentacoder has a lot of cowboys
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Would you like me to send my standard contract schedule out, or would you prefer to haggle over the rates first?
"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
|
|
|
|
|
Lets say I have a few rows of rectangles.
I would like my mouse to:
1. Select a rectangle using left click.
2. Shift + click to select multiple rectagles.
3. Ctrl + click to select multiple rectangles.
4. Press and hold to create a boundry and select all the rectangles within that boundary.
How should I go about? I do not have any source code now as I am still thinking how to select.
Thank you very much in advance.
|
|
|
|
|
Zar Ni wrote: How should I go about?
Try Googling for things like mouseevent and your language of choice; you will find many examples.
|
|
|
|
|
hi,
override OnKeyPress ,OnMouseClick, OnMouseMove
write a Control[] GetHittedControls(int x, int y)
if in OnMouseClick left button is pressed, set a private var LeftMouseDown = true
if in OnKeyPress Shift/Ctrl is pressed, set a private var ShiftOrCtrlPressed = true
in OnMouseMove check these two vars for true then call GetHittedControls()
in GetHittedControls iterate through all child controls of your form -> get the ClientRectanlge and call control.ClientRectangle.Contains(x,y) to indicate whether the control is focused or not..
add the control to a collection if is true and thats it ..
greets
|
|
|
|
|
Hi,
I am working on an application, which calls a WPF page in MFC exe and loads it too, but the backgound for the WPF is coming black.
here is code snippet
Declaration
using namespace System;
using namespace System::Windows;
using namespace System::Windows::Controls;
using namespace System::Windows::Media;
ref class Globals
{
public:
static System::Windows::Interop::HwndSource^ gHwndSource;
static WpfApplication1::Window1^ gwcContainer;
};
i have added in oninitdialog,
System::Windows::Interop::HwndSourceParameters^ sourceParams = gcnew System::Windows::Interop::HwndSourceParameters("MyWindowName");
sourceParams->PositionX = 20;
sourceParams->PositionY = 30;
sourceParams->ParentWindow = System::IntPtr(this->GetSafeHwnd());
sourceParams->WindowStyle = WS_VISIBLE | WS_CHILD;
System::Windows::Interop::HwndSource^ source = gcnew System::Windows::Interop::HwndSource(*sourceParams);
source->SizeToContent = System::Windows::SizeToContent::WidthAndHeight;
Globals::gwcContainer = gcnew WpfApplication1::Window1();
FrameworkElement^ myPage = Globals::gwcContainer;
source->RootVisual = myPage;
I dont want the black color around.
Any help is highly appriciated.
Thanks&Regards,
KDevloper
|
|
|
|
|
Recently I have began to receive this error message when I am trying to run or compile my programs, vb.net handles clause requires a withevents variable. This is occurring on all of my current projects that use the Handles clause. I understand that to remedy this I just need to add the Protected WithEvents Button1 As... code. My question is why is this happening since the designer should, and is, doing this in its self. is there something that is occurring with my visual studios 2008(full) that is causing this problem? Are the any other reasons that could cause this such as tourtiseSVN?
modified 8-Sep-21 21:01pm.
|
|
|
|
|
Hi,
I'm new to the CLR Profiler. When I generate 20 instances of a form while running the CLR Profiler I get the following results:
Allocated bytes: 20 instances of the form
Final heap bytes: 12 instances of the form
Objects finalized: 19 instances of the form
I would expect that an instance of the form is either in the final heap or finalized, so those numbers should count up to 20 and not 31. On the other hand, if there are indeed 31 instances (due to bad programming ), then I would expect that there are 31 instances allocated instead of 20.
Can someone help me interpret those numbers?
Thanks!
|
|
|
|
|
|
Hi,
First of all I found lot of article about this. Iam trying to solve it about few days without results.
I work on aplication, which should be something like report editor for printing.
I have a form with two scroll bars, grid and two rulers. Rulers and grid are User Controls.
For both controls I call:
Me.SetStyle(ControlStyles.AllPaintingInWmPaint + ControlStyles.UserPaint + ControlStyles.Opaque _
+ ControlStyles.OptimizedDoubleBuffer, True)
UpdateStyles() befor drawing.
The grid drawing function:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim rcPaper = New Rectangle(nGrid * nPaperOffset, nGrid * nPaperOffset, _
nPaperWidth, _
nPaperHeight)
Dim bmp As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
Dim graph As Graphics
graph = Graphics.FromImage(bmp)
' Draw paper
rcPaper.Location = rcPaper.Location + ptScrollOffset
graph.Clear(Color.DarkGray)
graph.FillRectangle(Brushes.White, rcPaper)
graph.DrawRectangle(Pens.Black, rcPaper)
' Draw the grid.
If bShowGrid Then
For x As Integer = 0 To bmp.Width Step nGrid
For y As Integer = 0 To bmp.Height Step nGrid
graph.DrawLine(m_PenGrid, x, y, x + 0.5F, y + 0.5F)
Next y
Next x
End If
e.Graphics.DrawImage(bmp, 0, 0)
' Free object added
bmp.Dispose()
graph.Dispose()
Debug.Print("Grid:OnPaint")
End Sub Ruler draw function:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'MyBase.OnPaint(e)
Dim bmp As New Bitmap(Me.Width, Me.Height)
Dim graph As Graphics
graph = Graphics.FromImage(bmp)
graph.Clear(Color.White)
Dim rStRect As SizeF
Dim pOrigin As New PointF
Dim string_format As New StringFormat
If eStyle = ERulerStyle.rHorizontal Then
' Horizontal ruler
Dim y1 As Integer = Me.ClientSize.Height
Dim y2 As Integer = (2 * Me.ClientSize.Height) \ 3
Dim y3 As Integer = Me.ClientSize.Height \ 3
Dim y4 As Integer = 0
Dim x As Integer = 0
For i As Integer = 0 To Me.ClientSize.Width \ nGrid
If (i + nPaperOffset) Mod nStepsPerUnit = 0 Then
'If i > 0 Then
pOrigin.X = x
pOrigin.Y = y4
string_format.Alignment = StringAlignment.Center
rStRect = graph.MeasureString(CStr((i - nPaperOffset) / nStepsPerUnit), dFont, pOrigin, string_format)
graph.DrawString(CStr((i - nPaperOffset) / nStepsPerUnit), dFont, dBrush, _
x - rStRect.Width / 2 + 1 + ptScrollOffset.X, _
y4 + ptScrollOffset.Y)
ElseIf (i + nPaperOffset) Mod (nStepsPerUnit / 2) = 0 Then
graph.DrawLine(m_PenGrid, x + ptScrollOffset.X, y1 + ptScrollOffset.Y, _
x + ptScrollOffset.X, y3 + ptScrollOffset.Y)
ElseIf (i + nPaperOffset) Mod (nStepsPerUnit / nTicksNum) = 0 Then
graph.DrawLine(m_PenGrid, x + ptScrollOffset.X, y1 + ptScrollOffset.Y, _
x + ptScrollOffset.X, y2 + ptScrollOffset.Y)
End If
x += nGrid
Next i
' Show the mouse position.
If bSelecting Then
graph.DrawLine(m_PenRulerDrawing, nX, y1, nX, 0)
Else
graph.DrawLine(m_PenRulerNormal, nX, y1, nX, 0)
End If
Else
' Vertical ruler
Dim x1 As Integer = Me.ClientSize.Width
Dim x2 As Integer = (2 * Me.ClientSize.Width) \ 3
Dim x3 As Integer = Me.ClientSize.Width \ 3
Dim x4 As Integer = 0
Dim y As Integer = 0
For i As Integer = 0 To Me.ClientSize.Height \ nGrid
If (i + nPaperOffset) Mod nStepsPerUnit = 0 Then
If i > 0 Then
pOrigin.X = x4
pOrigin.Y = y
string_format.Alignment = StringAlignment.Center
rStRect = graph.MeasureString(CStr((i - nPaperOffset) / nStepsPerUnit), dFont, pOrigin, string_format)
graph.DrawString(CStr((i - nPaperOffset) / nStepsPerUnit), dFont, _
dBrush, x4 + (nWidth - rStRect.Width) / 2 - 2 + ptScrollOffset.X, _
y - rStRect.Height / 2 + ptScrollOffset.Y)
'e.Graphics.DrawLine(m_PenGrid, x1, y, x4, y)
End If
ElseIf (i + nPaperOffset) Mod (nStepsPerUnit / 2) = 0 Then
graph.DrawLine(m_PenGrid, x1 + ptScrollOffset.X, y + ptScrollOffset.Y, _
x3 + ptScrollOffset.X, y + ptScrollOffset.Y)
ElseIf (i + nPaperOffset) Mod (nStepsPerUnit / nTicksNum) = 0 Then
graph.DrawLine(m_PenGrid, x1 + ptScrollOffset.X, y + ptScrollOffset.Y, _
x2 + ptScrollOffset.X, y + ptScrollOffset.Y)
End If
y += nGrid
Next i
' Show the mouse position.
If bSelecting Then
graph.DrawLine(m_PenRulerDrawing, x1, nY, x4, nY)
Else
graph.DrawLine(m_PenRulerNormal, x1, nY, x4, nY)
End If
End If
e.Graphics.DrawImage(bmp, 0, 0, Me.ClientSize.Width, Me.ClientSize.Height)
' Free object added
bmp.Dispose()
graph.Dispose()
Debug.Print("Scroll:OnPaint")
End Sub I handle scroll event like this:
Private Sub OnVScroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles VScrollBar1.Scroll
ctrlVRuler.ScrollRuller(, e.NewValue)
'Debug.Print("Call ctrlVRuler.Invalidate")
'ctrlVRuler.Invalidate()
ctrlMyGrid.ScrollPaper(, e.NewValue)
'Debug.Print("Call ctrlMyGrid.Invalidate")
'ctrlMyGrid.Invalidate()
' Invalidate "parent" control
Invalidate(true)
End Sub
Then while I am running appliation and scrolling I get this text in Inmediate window:
Grid:OnPaint
Scroll:OnPaint
Grid:OnPaint
Scroll:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Scroll:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Grid:OnPaint
Scroll:OnPaint
The candency of Grid repaint is rapidly bigger.
I am quit sure I call redraw (invalidate) just from scroll event during scrolling.
What do you think about this? How can I tell GDI+ to finish one controls re-drawing and then start other?
modified on Wednesday, October 28, 2009 4:10 AM
|
|
|
|
|
I probably wouldn't be able to answer your problem even if I could read your code but I'll never know because I can't read it.
Please, please, please edit your post, highlight the code part and then click the '
code block ' widget just above the Text: box. Then apply some indentation and spacing to make the code more readable. Alternatively delete the code hit the code block widget and then cut the code from your editor and paste it between the tags added when you clicked the widget.
You are far more likely to get an answer if you do that.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Yes I see. I removed it from another thread copy/past and that causes that it lost formating.
|
|
|
|
|
cheers,
first of all i'm wondering why you create your own graphics object at each run of OnPaint, beware because you need to destroy your created object with graph.Dispose().. and the PaintEventArgs already gives you the Graphic object!! graph = e.Graphics!!
second the OnPaint Method will run if your Form or Control you are overriding the OnPaint will repaint.
To draw an image of the Grid do not use the OnPaint method on the Form! here you would paint something for the grid and not for subcontrols.. Create a Function GetGridImage() or some like.. that you will call if you want to get an net image of the grid..
third in the Scroll.OnPaint you can call Invalidate for the Owner Control to force the re-draw, please take a look at some usercontrols created from other users here to understand how to use the OnPaint methods.. in your Case the OnPaint will nothing paint on the grid so this is nesty! the function will be called every time you move your mouse or the owner control will be repainted.
hope i could help!
bless
|
|
|
|
|
So I will answer also in points.
For first:
I tried to draw with double buffer method. I found on internet something like this. I added dispose for bmp and grap objects. Doesn't help.
For second:
I am not sure if I understand what did you write. I try to explain it one more time. I have grid control (with its own drawing function). Later grid control will also draw some other objects, like text boxes, etc... So the main form uses its own OnPaint (without overwriting or handling, ruler and grid have its own overwritten OnPaint method).
For third:
I replaced two Invalidate (for each control) with one invalidate(true) for owner form. Doesn't help. Can you give me some good example of how to use overwriting of usercontrol OnPaint ?
From my point of view it looks like ctrGrid control receive an event to repaint itself. Meanwhile (lets say in same time) ctrlRuler receive an event to repaint itself.
Re-painting of grid (due drawing huge rectangles) takes longer time. During this time will come another request to repaint both controls. And it happens that, the only grid control is repainted.
I don't know why grid control has bigger cadence of of re-painting, maybe it was added to owner form first.
I also hope you will help.
|
|
|
|
|
aaalllriiiight i did not see the dispose in your code sorry
now i can read it much better ^^
in case your paper has a size of 2000x1000 but your controlsize is only 200x100 you draw the created bitmap on the control, so every time the OnPaint is called you will draw the hole paper (2000x1000) instead of only a region of the hole paper (size of 200x100, at Location.Y=1200, Location.X=1500) this needs a lot of time and the result will not be displayed..
i would need to see the hole project to understand your code logic and to face out why paint events will be raised too much..
|
|
|
|
|
In fact repainting is slow just when I call
graph.Clear(Color.DarkGray)
Grid size: 803x442
Parent size: 853x508
Where can I send an email ?
|
|
|
|
|
hmm i would apprechiate if you would upload to codeproject or some else and send me a link to download the file..
try to use FillRectanlge(graph rect, color.darkgray) instead of clear this might be a lot faster. your graphic object is empty and i think clear performs more than setting the color..
greetz
|
|
|
|
|