|
Skewed.
Quote: ' Size to src bm above - 1 pixel in width to allow for 1 pixel offset; height is the same.
Dim bmCrop As Bitmap = New Bitmap(bmSrc.Width - 1, bmSrc.Height, bmSrc.PixelFormat)
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
I have written two simple classes (clsMessage and clsHello). I create an instance of clsMessage and call the Message1 function passing the specific clsHello class that exposes the correct MessagBox to me. When call then Message2 function passing a generic object that expose the correct MessageBox.
these are the classes:
Public Class clsMessage
Public Function Message1(Of T As {clsHello, IHello})(ByVal value As String) As T
Return (New clsHello(value))
End Function
Public Function Message2(Of T)(ByVal value As String) As T
Return DirectCast((New clsHello(value)), Object)
End Function
End Class
Public Class clsHello
Implements IHello
Dim _value As String
Sub New(ByVal value As String)
_value = value
End Sub
Public Sub Hello() Implements IHello.Hello
Call MsgBox(String.Concat("Hello: ", _value))
End Sub
End Class
Public Interface IHello
Sub Hello()
End Interface
these are code that works:
Dim objMessage As New clsMessage
Dim objHelloSpecific As clsHello = objMessage.Message1(Of clsHello)("My name specific")
objHelloSpecific.Hello()
objHelloSpecific = Nothing
Dim objHelloGeneric As Object = objMessage.Message2(Of Object)("My name generic")
objHelloGeneric.Hello
objHelloGeneric = Nothing
objMessage = Nothing
But if using reflection not works and I don't know how to write the invoke method:
Dim typMessage As System.Type = Reflection.Assembly.GetExecutingAssembly.GetType("WindowsApplication1.clsMessage")
Dim typHello As System.Type = Reflection.Assembly.GetExecutingAssembly.GetType("WindowsApplication1.clsHello")
Dim refMessage As Object = typMessage.GetConstructor({}).Invoke({})
Dim funHelloSpcecific As Reflection.MethodInfo = typMessage.GetMethod("Message1")
Dim funHelloGeneric As Reflection.MethodInfo = typMessage.GetMethod("Message2")
Try
Dim refHelloSpecific As Object = funHelloSpcecific.Invoke(Nothing, {"My name specific"})
refHelloSpecific.Hello()
refHelloSpecific = Nothing
Catch ex As Exception
Call MsgBox(String.Concat("refHelloSpecific: ", ex.Message))
End Try
funHelloSpcecific = Nothing
Try
Dim refHelloGeneric As Object = funHelloGeneric.Invoke(Nothing, {"My name generic"})
refHelloGeneric.Hello
refHelloGeneric = Nothing
Catch ex As Exception
Call MsgBox(String.Concat("refHelloGeneric: ", ex.Message))
End Try
funHelloGeneric = Nothing
refMessage = Nothing
typHello = Nothing
typMessage = Nothing
The error is: Impossibile eseguire operazioni con associazione tardiva in tipi o metodi per i quali ContainsGenericParameters è true (Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true)
question: can someone help me to write the invoke method correctly? thank you.
Giorgio
|
|
|
|
|
You have a reference to the unbound generic method. You need to call MakeGenericMethod[^] to provide the type parameters.
You're also passing Nothing as the first parameter to Invoke . That will only work for Shared methods. You need to pass the instance of your clsMessage class to invoke a method on that instance.
Dim funHelloSpcecific As Reflection.MethodInfo = typMessage.GetMethod("Message1").MakeGenericMethod(typHello)
Dim refHelloSpecific As IHello = DirectCast(funHelloSpcecific.Invoke(refMessage, {"My name specific"}), IHello)
refHelloSpecific.Hello()
Dim funHelloGeneric As Reflection.MethodInfo = typMessage.GetMethod("Message2").MakeGenericMethod(typHello)
Dim refHelloGeneric As IHello = DirectCast(funHelloGeneric.Invoke(refMessage, {"My name generic"}), IHello)
refHelloGeneric.Hello()
Reflection (Visual Basic) | Microsoft Docs[^]
Generic Procedures in Visual Basic | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
wow, i'ts work!!! thanks so much
|
|
|
|
|
hi,
i want to change color txt in messagebox with API
i try so many i spent 10 hours to research of this issue
|
|
|
|
|
You can't change the style of the MessageBox ; it's controlled by the current Windows theme.
You'll have to create your own form to display your message. For example: Custom Message Box in VC#[^]
(The code is in C#, but it should be fairly easy for you to convert it to VB.NET if required.)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello !
I'm using vb.net 2017 and EF 6.
I have a bindingsource and also datagrid that is bound to this bindingsource.
I need a way to clear all the items from bindingsource to empty it , but without deleting from database.
I've tried
Bindingsource1.Datasource=Nothing.
But , after calling this , the datagrid still have all the bindingsource items.
|
|
|
|
|
You need to call the Refresh method to repaint the grid.
|
|
|
|
|
I've tried also
Bindingsource.Clear
Bindingsource.Clear Bindingsource.Clear ,
this is working , but does this remove also from database ( if I call savechanges for example ?)
|
|
|
|
|
You should not use savechanges unless you want the database updated.
|
|
|
|
|
ok , but Bindingsource.clear only remove items from bindingsource or also mark them for deletion from database ?
|
|
|
|
|
Sorry, I don't know the answer. You could study the documentation, or write a simple test program to try it out.
|
|
|
|
|
<datagrid>.DataSource = Nothing
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Hello !
I'm using vb.net 2017 and Entity Framework 6.
Is there any way to update only one table in model from database ?
I try to right click on model.edmx and choose Update model from database , but this way update and recreate the entire model.
I've tried also to delete only the table that I've changed on database , and after I choose Update model from database and after on ADD I select only this table , but after the entire model is recreated.
How can I do ?
|
|
|
|
|
I have a ListView with OwnerDraw enabled and I am processing just DrawItem().
I am using LargeImageList with 48 x 48 ImageSize and View = MediumIcons.
When I rename an item to cause the text to wrap and thereby causing the height
of the item to increase, every thing is ok while the item is selected; ie. Has Focus.
When I select a different item and the renamed item loses focus, e.bounds reports
a reduced height which causes misalignment of text.
Note: This does not occur when wrapping results with 2 lines. But does occur when there are 3 lines.
What am I missing?
Thank you
Private Sub OpenFileDialogListView_DrawItem(ByVal sender As Object, ByVal e As DrawListViewItemEventArgs) Handles MyBase.DrawItem
' Start of function. No preceding code.
' If I break here when item is selected, e.bounds.height = 94.
' When not selected, e.bounds.height = 81.
e.DrawBackground()
End Sub
-- modified 28-May-19 12:24pm.
|
|
|
|
|
I have a similar app written in C++. When the view is in "Large Icon" mode then the text is restricted to two lines (with a trailing ellipsis). However, when an item is focused it shows all three lines. Thus the height of the item varies between focused and unfocused.
|
|
|
|
|
You beat me. I just created a test app in Mfc myself and found that out.
I was confused because Explorer somehow displays 3 lines. Must be custom control
because Spy does not show what kind of control it is.
Thanks a for your help.
|
|
|
|
|
Hi,
I'm used to make Excel add-ins with vba (xlam files). There I can place my button wherever I want. New or old tab, new or old group. Now I have made an vb.net add-in and I want to place my button into a specific group. I already managed to place it into the right tab and after the group but I want it into that group. Can this been done? if yes how?
Thanks Jan
|
|
|
|
|
|
I'm using entity Framework 6.
On my database I have these tables :
MasterTable ( Id , name)
Child1 ( ID , name , vl1 , Master_ID)
Child2 ( ID , name , vl2 , MasterID )
Child3 (ID , name , vl3 , Master_ID )
Child3Itm ( ID , name , Child3_ID)
For a given `MasterTable` item, I want to load with a single Query from database:
- All `Child1` where `vl1 > 5`
- All `Child2` where `vl2 > 6`
- All `Child3` where `vl3 > 7`
And in each `Child3` to load all of the `Child3Itm` content.
I'm using this query:
Dim lst = (From t In context.MasterTable.Where(Function(t1) t1.id = 7)
Select New With {
t,
.chld1 = t.child1s.Where(Function(t21) t21.vl1 >5),
.chld2 = t.child2s.Where(Function(t31) t31.vl2>6 ),
.chld3 = t.child3s.Where(Function(t41) t41.vl3>7).Select(Function(t411) t411.Child3Itms)
}).ToList
The problem is that no `Child3` are selected. All others are OK.
What can i do?
Thanks in advance!
modified 16-May-19 13:35pm.
|
|
|
|
|
How about:
.chld3 = t.child3s.AsQueryable().Include(Function(t411) t411.Child3Itms).Where(Function(t41) t41.vl3 > 7)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Now i'm getting an error :
System.NotSupportedException: 'LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[Myprog.Child3] Include[child3,ICollection`1](System.Linq.IQueryable`1[Myprog.Child3], System.Linq.Expressions.Expression`1[System.Func`2[Myprog.Child3,System.Collections.Generic.ICollection`1[Myprog.Child3itm]]])' method, and this method cannot be translated into a store expression.'
|
|
|
|
|
I've found 2 solutions that are working. Can someone tell me which is better ?
Solution 1
Dim lst = (From t In context.MasterTable.Where(Function(t1) t1.id = 7)
Select New With {
t,
.chld1 = t.child1s.Where(Function(t21) t21.vl1 >5),
.chld2 = t.child2s.Where(Function(t31) t31.vl2>6 ),
.chld3 = t.child3s.Where(Function(t41) t41.vl3>7),
.chld3itms = t.child3s.Where(Function(t51) t51.vl3>7).Select(Function(t511) t511.Child3Itms)
}).ToList
Solution 2
Dim lst = (From t In context.MasterTable.Where(Function(t1) t1.id = 7)
Select New With {
t,
.chld1 = t.child1s.Where(Function(t21) t21.vl1 >5),
.chld2 = t.child2s.Where(Function(t31) t31.vl2>6 ),
.chld3 = (From t2 in t.child3s.Where(Function(t41) t41.vl3>7)
Select New With {
t2,
.chld3it=t2.Child3Itms
})
}).ToList
|
|
|
|
|
Neither, they do the exact same thing. It's up to your preference.
|
|
|
|
|
I mean better for performance and the complexity of sql query that is generated in each case..
|
|
|
|