ppt Slide and textbox selection macros - textbox

I want to make a PowerPoint macro. This is a macro that selects with textbox slide number, left, top.
'for example
Sub test1()
ActivePresentation.Slides(1).Select
with Left:=-300, Top:=100
End With
Dim TBox1
TBox1 = ActiveWindow.Selection.TextRange.Text
MsgBox (TBox13) '----error
End Sub
'select text box

Here's some sample code that'll do what you want.
Rather than make it specific to your question, I wrote something more general-purpose that you can use to find any shape at any position on any slide you like.
Option Explicit
Sub AddTestTextbox()
' Use this to quickly add a text box to test with
' at the right coordinates
Dim oSh As Shape
With ActivePresentation.Slides(1)
Set oSh = .Shapes.AddTextbox(msoTextOrientationHorizontal, 300, 100, 200, 100)
oSh.TextFrame.TextRange.Text = "Some random text to test with"
End With
End Sub
Sub Test()
Dim oSh As Shape
Set oSh = FindShapeAt(ActivePresentation.Slides(1), 300, 100)
If Not oSh Is Nothing Then
If oSh.HasTextFrame Then
If oSh.TextFrame.HasText Then
MsgBox oSh.TextFrame.TextRange.Text
End If
End If
End If
End Sub
Function FindShapeAt(oSl As Slide, sngLeft As Single, sngTop As Single) As Shape
Dim oSh As Shape
For Each oSh In oSl.Shapes
If oSh.Left = sngLeft Then
If oSh.Top = sngTop Then
Set FindShapeAt = oSh
Exit Function
End If
End If
Next
End Function

Related

Using link_annotation with :Desc option in Prawn PDF

I have been struggling to link a text heading with a specific page in the Pdf, similar to the linking of Table of Contents in the Pdf file. I have found link_annotation method to achieve this however there isn't suffice documentation/examples available to use link_annotation method with :Desc option.
Any ideas how to use link_annotation with :Desc option?
Link Annotation Documentation: https://www.rubydoc.info/gems/prawn-core/Prawn%2FDocument%2FAnnotations:link_annotation
For linking text to specific page at specific offset, Destinations
class provide many helper methods. By using dest_xyz, text can be linked to specific page at specific offset.
Here is the working example which links text from 1st page to text at 2nd page at specific offset.
require 'Prawn'
margin = 36.0
extra_clickable_margin = 4.0
top_offset = 500.0
#pdf = Prawn::Document.new(margin: margin, page_size: 'A4')
clickable_text = "Clickable Annotation to 2nd page at offset #{top_offset}"
text_width = #pdf.width_of(clickable_text)
text_height = #pdf.height_of(clickable_text)
cursor = #pdf.cursor
#pdf.text clickable_text
left = margin
top = cursor + margin + extra_clickable_margin
bottom = top - text_height - extra_clickable_margin
right = left + text_width
src_rect = [left, bottom, right, top]
#pdf = Prawn::Document.new(margin: margin, page_size: 'A4')
#pdf.start_new_page
#pdf.text 'Some Text for 2nd page. ' * 40
dest = #pdf.dest_xyz(0, top_offset, nil, #pdf.state.pages[1])
#pdf.link_annotation(src_rect, Dest: dest)

Vertical Scroll bar for Top and Bottom Legends

I want to align my legend to the Bottom of my chart because the no of Character present in my legend are around 100.
Please let me know how I can provide a vertical toolbar to that so that legend box size remains constant also whether there is a way we can round off the Text in label.
Thanks
Akshay
The tcLegendScrollBar tool is designed to show the items in the legend that don't fit in the legend rectangle, not to limit the number of characters shown in the items. Here it is an example usign it:
Private Sub Form_Load()
TChart1.Aspect.View3D = False
Dim i As Integer
For i = 0 To 10
TChart1.AddSeries scFastLine
TChart1.Series(i).FillSampleValues 10
TChart1.Series(i).Title = "this is a very very veeeeeeery long string to be shown in the legend as title for the series " + Str$(i)
Next i
TChart1.Legend.MaxNumRows = 5
TChart1.Tools.Add tcLegendScrollBar
End Sub
To limit the length of the strings in the legend you can use the OnGetLegendText event. Ie:
Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
LegendText = Left$(LegendText, 10) + "..."
End Sub

TeeChart On Mouse Over a series display a user define Image

My requirement is I want to display a Image box when a user perform a mouse over on a bar in the chart. Currently in mouse over we are displaying the text such as label, Percentage etc can we display Image as well.
Thanks
Akshay
You can use a hidden Rectangle tool to show the desired image and use the provided events to change its visibility, position, or the image loaded.
Ie, using OnMouseEnterSeries/OnMouseLeaveSeries, but the same could be done with OnMouseMove event:
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scBar
TChart1.Series(0).FillSampleValues
TChart1.Tools.Add tcMarksTip
TChart1.Tools.Add tcRectangle
TChart1.Tools.Items(1).Active = False
TChart1.Tools.Items(1).asRectangle.AllowDrag = False
TChart1.Tools.Items(1).asRectangle.AllowResize = False
TChart1.Tools.Items(1).asRectangle.Shape.Transparency = 0
End Sub
Private Sub TChart1_OnMouseEnterSeries(ByVal SeriesIndex As Long)
ValueIndex = TChart1.Series(SeriesIndex).Clicked(TChart1.MousePosition.X, TChart1.MousePosition.Y)
If ValueIndex = 2 Then
TChart1.Tools.Items(1).Active = True
TChart1.Tools.Items(1).asRectangle.Shape.Picture.LoadImage "C:\tmp\ImageForValueIndex2.png"
TChart1.Tools.Items(1).asRectangle.Left = TChart1.MousePosition.X
TChart1.Tools.Items(1).asRectangle.Top = TChart1.MousePosition.Y
End If
End Sub
Private Sub TChart1_OnMouseLeaveSeries(ByVal SeriesIndex As Long)
TChart1.Tools.Items(1).Active = False
End Sub
Edit:
As noticed in the comment below, TeeChart VCL v2014.11 introduced SystemHints property as explained here:
MarksTip tool new property SystemHints (boolean default True in VCL,
False in Firemonkey). When False, a normal TeeShape object is used to
paint the tiptool instead of using the VCL system mechanism.
ChartTool3.SystemHints := False;
ChartTool3.Format.Font.Size:=14;
The only disadvantadge compared to system hints is the shape cannot be
displayed outside the chart bounds.
When SystemHints is False, the new Format property (of type TTeeShape)
contains all the formatting properties (Brush, Pen, Font, etc) to
display the hint.
Since TeeChart ActiveX is a wrapper from TeeChart VCL, you can use this new feature from TeeChart ActiveX v2014.0.0.1.
So you just have to keep in mind to set SystemHints to False if you want to use the TeeShape properties. Here it is a simple example:
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scBar
TChart1.Series(0).FillSampleValues
TChart1.Tools.Add tcMarksTip
TChart1.Tools.Items(0).asMarksTip.Format.Picture.LoadImage "C:\tmp\ImageForAllValues.jpg"
TChart1.Tools.Items(0).asMarksTip.SystemHints = False
End Sub

on_touch_down problems with dynamic created widgets in kivy

I'm new to kivy and need some assistance with the following problem. I adding numbers/operators as widgets (labels) dynamically and at a random position to a layout(FloatLayout). The idea is that when I clicked on a number/operator it will draw a circle around the number/operator. I get some very strange behaviour. Does not matter what number/operator I click the selection circle is only drawn around the last added label. Then to confuse me even more the other number/operator is circled if I press on some random point on the screen
following is the core of my code:
class SelectedObject(Label):
selected = BooleanProperty()
refresh = BooleanProperty()
def __init__(self, **kwargs):
super(SelectedObject, self).__init__(**kwargs)
self.center_x = randint(0, Window.width/2)
self.center_y = randint(0, Window.height/2)
self.bind( refresh = self.redraw )
def redraw(self, *args):
#print('Redraw for: ' + self)
self.canvas.after.clear()
if self.selected:
with self.canvas.after:
Line(circle=(self.center_x, self.center_y, 20))
self.canvas.ask_update()
def on_touch_down(self, touch):
print("touch#: " + str(touch))
if not self.collide_point(touch.x, touch.y):
return False
print("yip: " + self)
self.selected = not self.selected
self.refresh = not self.refresh # force a redraw
return True
class GameNumber(SelectedObject):
pass
class Operator(SelectedObject):
pass
class GameApp(App):
numberArr = ListProperty([])
operatorArr = ListProperty([])
def build(self):
f = FloatLayout()
#populate numberArr and operatorArr
self.buildLevel()
for number in self.numberArr:
numberItem = GameNumber(text = str(number))
f.add_widget(numberItem)
for operator in self.operatorArr:
f.add_widget(Operator(text = operator))
return f
The problem here is that you have not set sizes to the labels. So each label takes up as much space as it can and the last label being on top, it gets the circle.
You need to pass each GameNumber and Operator some sort of size_hint and/or size. For example, if you want each label to be 10 by 10, you can do something like this: numberItem = GameNumber(text=str(number), size_hint=(None, None), size=(10, 10)). You can set their size relative to the window size by for example setting size_hint=(0.1, 0.1).
Remember that size_hint is always (1, 1) by default, so you need to change it something else if you want your widgets to be smaller than the space of the container and set size_hint=(None, None) if you want to set a fixed size yourself.
If you want to position the labels randomly around the screen, take a look at pos_hint, which is more convenient than playing with the size of the window directly. Also, remember that there's a chance that multiple labels might get on top of each other or at the very borders of the window or even outside if you are not careful.
EDIT: To help you find the source of these kind of problems (that usually relate to layout issues), take a look at Kivy Widget Area Display

Highlight specific words in a RichTextBox

How can i do this: I press on a button and then it finds every occurrence of the word let's say "test" and changes the word's fore color to aqua...
txtText.Find("dim")
txtText.SelectionColor = Color.Aqua
If i do this it only finds the first occurrence, makes it aqua and if i press it again it turns all the text like that. Can anyone help me?
You can write this code, to do that:
First you need button(FindBUT), and RichTextBox(TextBox)
Public Class Research
Private Sub FindBUT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindBUT.Click
'Check button text
If FindBUT.Text = ("Find ""dim""") Then
'Return all text color to black
TextBox.ForeColor = Color.Black
'Find "dim" word
TextBox.Find("dim")
TextBox.SelectionColor = Color.Aqua
'change button text to ("Find all")
FindBUT.Text = ("Find all")
'Check button text
ElseIf FindBUT.Text = ("Find all") Then
'change all text color to Aqua
TextBox.ForeColor = Color.Aqua
'change button text to ("Find ""dim"" ")
FindBUT.Text = ("Find ""dim""")
End If
End Sub
End Class

Resources